Question

Query Gives O/p as

ItemSizeNM

(colName)

'U','V','X','Y'

But when I used this as input to IN Query in the Code Which I did. It Doesn't Gives same resultset. Why This Happens...? Table MstItemSize Has Proper Data.

 declare @tblRingSize table ( ringSize varchar(100))        
     declare  @ringSize varchar(100)         
     select   @ringSize= cast((otherringSize) as varchar) 
     from ##tempBand  where styleNo='BD00002';   
  1. INSERT INTO @tblRingSize SELECT Item FROM dbo.SplitStrings_CTE (@ringSize, ',');

  2. select ItemSizeNm from MstItemSize where SizeTypeNm ='Ring' and
    ItemSizeNm
    in --('U','V','X','Y')

    ( select Replace ( (select STUFF( (select ''',''' + ringSize from @tblRingSize For XML PATH('')),1,2,'') +'''' ) ,' ',''))

  3. select Replace ( (select STUFF( (select ''',''' + ringSize from @tblRingSize For XML PATH('')),1,2,'') +'''' ) ,' ','')

Was it helpful?

Solution

You don't need to use STUFF, FOR XML, or REPLACE for the subquery:

select 
    ItemSizeNm 
from 
    MstItemSize 
where SizeTypeNm ='Ring' 
and ItemSizeNm  in (select ringSize from @tblRingSize)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top