Select with "IN" clause

  • Hi everyone,

    Please, some light over my problem...

    I´m executing the query:

    declare @dir varchar

    SET @dir = '4, 2'

    SELECT *, empresa FROM DIRETORIAS WHERE (empresa IN (@dir))

    The problem is that only the first record is showed "4", if I change to '2, 4' only one record is showed, too, "2".

    Thanks in advance. Best

    Daniel

  • Please don't cross post. It just wastes peoples time and fragments replies.

    No replies to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic1105123-149-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • phele table se select karo , fir usmese kaam ki cheeze khich kar nikalo,2bar + 3bar_karo and:hehe: u got ur result:-P:w00t::cool::hehe::-D:-):-P

  • You can't use a list in a varchar like this. Use a table instead:

    declare @dir table (d varchar)

    insert into @dir select '4' union select '2'

    SELECT *, empresa FROM #DIRETORIAS WHERE empresa IN (select * FROM @dir)

  • Hi kipb-world,

    Thank you very much, works fine!

    Best,

    Daniel

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply