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

来源:学生作业帮助网 编辑:六六作业网 时间:2024/05/21 00:24:12
sql语句中where字段in(''1'',''2'',''3'')这个in括号里的值有效但我先定义一个字符串@str=''''''1'''',''''2'''',''''3''''''where字段in(@str)这样失败了,求帮助sql

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)