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)
...全文
128 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧