sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/17 16:09:31
sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助
xRJAIU{ VCzY DV =D$=AQĚ]%Db|a9s]g8P d \ $A34Exr *>l=Tw}-"?uZjؕm4&;$Co˰a+}3VsO5Szt:7<ʹW0Wn%YPvdv≬XT]76Nfx /&p#.0]\Y۱߶-Z S0X,]>9Udתgq3NlJ =ˍ wy

sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助
sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助

sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助
create table #temp(code varchar(20))
\x09\x09\x09\x09\x09\x09insert into #temp select '1'
\x09\x09\x09\x09\x09\x09insert into #temp select '4'
\x09\x09\x09\x09\x09\x09insert into #temp select '3'
\x09\x09\x09\x09\x09\x09insert into #temp select '2'
\x09\x09\x09\x09\x09\x09
\x09\x09\x09\x09\x09\x09declare @str varchar(20)='''1'',''2'',''3'''
\x09\x09\x09\x09\x09\x09declare @lsql varchar(100)\x09\x09\x09\x09\x09\x09
\x09\x09\x09\x09\x09\x09set @lsql = 'select * from #temp where code in ('+@str+')'
\x09\x09\x09\x09\x09\x09exec (@lsql)