Inline SQL execution problem

  • The following returns to the results pane a SQL statement that I can put in query analyzer myself, run, and get the desired results (a temp table created with the IDs in question). But, it won't execute in-line.

    I'm truly stuck. It's giving me an error stating that:

    The name 'Select ID into ##IDs FROM tblMasterR WHERE id in (668125, 176026, 218834, 269831, 663539, 340306, 230372, 620885, 501105, 353093, 698004, 684082, 394087)' is not a valid identifier.

    Again, if I take what's between the ' ' and run it - it works fine, but in the following SQL, it won't work.

    Any ideas?

    Declare @IDs as varchar(2000)

    Declare @SQL2 as varchar(5000)

    Set @IDs = '668125, 176026, 218834, 269831, 663539, 340306, 230372, 620885, 501105, 353093, 698004, 684082, 394087'

    set @SQL2 = 'Select ID into ##IDs FROM tblMasterR WHERE id in (' + @IDs + ')'

    print @SQL2

    Exec @SQL2

    BT
  • HI

    Exec (@SQL2)  is correct .it is not like this Exec @SQL2

    Regards

    padmakumar

     

  • PAD - thanks.. it worked!

    BT

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

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