当前位置: 代码迷 >> Sql Server >> 高手求救,一个SQL语句~该怎么解决
  详细解决方案

高手求救,一个SQL语句~该怎么解决

热度:8   发布时间:2016-04-27 20:36:12.0
高手求救,一个SQL语句~~~~~~~~~~~~~
declare   @s   varchar(10)
declare   @t   varchar(100)
select   @s= ' ' '8032 ' ' '
select   @t= ' ' '3401 ' ', ' '3402 ' ' '

SELECT   TOP   10   *     from   INVTAA
                                  where   TAA002   [email protected]   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= '[email protected]+ ' and TAA003 in( '[email protected]+ ') ')
------解决方案--------------------
改用Charindex

declare @s varchar(10)
declare @t varchar(100)
select @s= '8032 '
select @t= '3401,3402 '

SELECT TOP 10 * from INVTAA
where TAA002 [email protected] 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 = '[email protected]+ ' and TAA003 in( '[email protected]+ ') ')

  相关解决方案