Using select where in with variable

  • Hi all,

    I need to replace a situation like this:

    select x from y where id in (1,2,3,)

    where id is an int

    with something like this

    select x from y where id in (select id_values from z)

    where id_values is a varchar that has a comma delimited string of ids so it looks like this '1,2,3'

    I'm getting the Syntax error converting the varchar value.. msg

    I know the test_expression (y) needs to be the same data type as the values in the comma seperated list but since that has to be a string data type I'm stumped.

  • Look here ...

    http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=835

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Thanks so much, works great!

Viewing 3 posts - 1 through 3 (of 3 total)

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