sql字符拼接变量

snlixing 2019-12-24 04:15:49

i=10

sql="select planday"+i+" from table"

想得到结果sql="select planday10 from table"


sql字符拼接变量这样不对呢
...全文
247 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gw6328 2019-12-26
  • 打赏
  • 举报
回复
感觉没问题!
snlixing 2019-12-26
  • 打赏
  • 举报
回复
引用 6 楼 吉普赛的歌 的回复:
你到底是在 sqlserver 中做拼接, 还是后台语言中做拼接?


大佬,我在后台拼接
吉普赛的歌 版主 2019-12-25
  • 打赏
  • 举报
回复
你到底是在 sqlserver 中做拼接, 还是后台语言中做拼接?
snlixing 2019-12-24
  • 打赏
  • 举报
回复

DS(" planday"+convert(varchar,@i)+" ,"PlanTable","")

我把语句封装在里面,提示无效字符

DS 定义如下:
function DS(string field,string tablename,string where)
snlixing 2019-12-24
  • 打赏
  • 举报
回复
引用 3 楼 文盲老顾 的回复:

declare @i int,@sql nvarchar(max)
select @i=10

set @sql="select planday"+convert(varchar,@i)+" from table"

想得到结果sql="select planday10 from table"


这个i的值是request接收到的值,然后赋值给sql语句的
文盲老顾 2019-12-24
  • 打赏
  • 举报
回复

declare @i int,@sql nvarchar(max)
select @i=10

set @sql="select  planday"+convert(varchar,@i)+" from table"

想得到结果sql="select  planday10  from table"
独木成林_ 2019-12-24
  • 打赏
  • 举报
回复
引用 1 楼 独木成林_ 的回复:


DECLARE @str varchar(2000)
SET @str = '10'
@str="select  planday"+@str+"  from table"
Select @str
將第一行調整為DECLARE @str varchar(2000)
独木成林_ 2019-12-24
  • 打赏
  • 举报
回复


DECLARE @str varchar(20)
SET @str = '10'
@str="select  planday"+@str+"  from table"
Select @str

34,588

社区成员

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

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