高手求救,一个SQL语句~~~~~~~~~~~~~
declare @s varchar(10)
declare @t varchar(100)
select @s= ' ' '8032 ' ' '
select @t= ' ' '3401 ' ', ' '3402 ' ' '
SELECT TOP 10 * from INVTAA
where TAA002 =@s and TAA003 in(@t)
查询不出数据~~~~~~
而这个语句缺可以查询出数据
SELECT TOP 10 * from INVTAA
where TAA002= '8032 ' and TAA003 in( '3401 ', '3402 ')
请问是为什么呢?
------解决方案--------------------declare @s varchar(10)
declare @t varchar(100)
select @s= ' ' '8032 ' ' '
select @t= ' ' '3401 ' ', ' '3402 ' ' '
EXEC( 'SELECT TOP 10 * from INVTAA where TAA002= '+@s+ ' and TAA003 in( '+@t+ ') ')
------解决方案--------------------改用Charindex
declare @s varchar(10)
declare @t varchar(100)
select @s= '8032 '
select @t= '3401,3402 '
SELECT TOP 10 * from INVTAA
where TAA002 =@s and CharIndex(TAA003,@t) > 0
------解决方案--------------------declare @s varchar(10)
declare @t varchar(100)
select @s= ' ' '8032 ' ' '
select @t= ' ' '3401 ' ', ' '3402 ' ' '
exec( '
SELECT TOP 10 * from INVTAA
where TAA002 = '+@s+ ' and TAA003 in( '+@t+ ') ')