导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

sql语句怎么连接数字类型变量?

yzxlyl 2003-12-23 03:29:38
declare @Strsql varchar(2000),@iagefrom int,@iageto int
set @iagefrom=25
set @iageto=100
set @Strsql='select * from members where age between '''+iagefrom+''' and '''+iageto+''''
--这样不行
--这种方法只适合字符串类型的变量,但数字类型的变量有问题,数字类型的 变量该怎么连接呢?

exec(@Strsql)
...全文
68 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hmily1688 2003-12-23
就是cast或convert进行转换
具体用法可以查帮助
回复
gmlxf 2003-12-23
declare @Strsql varchar(2000),@iagefrom int,@iageto int
set @iagefrom=25
set @iageto=100
set @Strsql='select * from members where age between '+cast(@iagefrom as varchar)+' and '+cast(@iageto as varchar)
exec(@Strsql)
回复
devilwind 2003-12-23
declare @Strsql varchar(2000),@iagefrom int,@iageto int
set @iagefrom=25
set @iageto=100
set @Strsql='select * from members where age between '+cast(@iagefrom as varchar(10))+' and '+cast(@iageto as varchar(10))
select @Strsql
exec(@Strsql)
回复
gmlxf 2003-12-23
declare @Strsql varchar(2000),@iagefrom int,@iageto int
set @iagefrom=25
set @iageto=100
set @Strsql='select * from members where age between '+cast(@iagefrom as varchar)+' and '+cast(@iageto as varchar)
print @Strsql
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告