Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Posts
    17

    Lightbulb Unanswered: [ASK] -What is different??

    I have variable @temp = 'abc','bcd','cde'

    if i query like this it works

    select * from Table where field1 IN ('abc','bcd','cde')

    but it's not work when i used this

    select * from Table where field1 IN (Select @temp)
    OR
    select * from Table where field1 IN (Select @temp)

    Anyone could give any solution ?? please...Thanks In Advance

    Regards,
    Thomas Benny

  2. #2
    Join Date
    Dec 2008
    Posts
    135
    if it is a variable
    declare @temp
    select @temp = 'abc,bcd,cde'
    select * from table where '%'+@temp+'%' like '%'+field1+'%'

    if it is a table then use this

    select * from Table
    inner join
    @temp t on '%'+t.col+'%' like '%'+ field1+'%'
    Last edited by bklr; 02-17-09 at 05:56.

  3. #3
    Join Date
    Feb 2009
    Posts
    17

    Thumbs up Thanks Again...

    Again...for @BKLR...thanks again and again for the solution...u r Marvelous...and i will not quit to say thanks again and again.....
    may your help always be with us (people with the blindness) and more


    -=CASE CLOSED=-


    Regards,
    Thomas Benny
    Last edited by bny; 02-17-09 at 23:41.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Just so you know, the solution posted is very innefficient and will not scale well at all. If this is of no concern to you then feel free to implement it in production... if performance is a concern then you have to explore other options.

    My suggestion is a TVF that splits the values which you can then join to in your final query.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •