sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/04 12:10:29
![sql语句中 where 字段 in ('1','2','3') 这个in括号里的值有效 但我先定义一个字符串@str='''1'',''2'',''3''' where 字段 in (@str)这样失败了,求帮助](/uploads/image/z/15126635-11-5.jpg?t=sql%E8%AF%AD%E5%8F%A5%E4%B8%AD+where+%E5%AD%97%E6%AE%B5+in+%28%271%27%2C%272%27%2C%273%27%29+%E8%BF%99%E4%B8%AAin%E6%8B%AC%E5%8F%B7%E9%87%8C%E7%9A%84%E5%80%BC%E6%9C%89%E6%95%88+%E4%BD%86%E6%88%91%E5%85%88%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%40str%3D%27%27%271%27%27%2C%27%272%27%27%2C%27%273%27%27%27+where+%E5%AD%97%E6%AE%B5+in+%28%40str%29%E8%BF%99%E6%A0%B7%E5%A4%B1%E8%B4%A5%E4%BA%86%2C%E6%B1%82%E5%B8%AE%E5%8A%A9)
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)