Results 1 to 2 of 2

Thread: string to int convert

  1. #1
    jim Guest

    string to int convert


    declare @x varchar(8000)
    set @x = '1001,1002,1003'
    select * from tbl1 where col1 in (@x)
    Result - "Syntax error converting the varchar value '1001,1002,1003' to a column of data type int."

    Tbl1.col1 is an int data type. I understand why I'm getting the error but how can I build the select statement so this will work?

    Thanks,

    Jim

  2. #2
    Chris Thibodeaux Guest

    string to int convert (reply)

    declare @x varchar(8000), @sql varchar(8000)
    set @x = '1001,1002,1003'
    set @sql = 'select * from tbl1 where col1 in ('+@x+&#39'
    --select @sql
    exec(@sql)


    ------------
    jim at 3/5/01 1:37:57 PM


    declare @x varchar(8000)
    set @x = '1001,1002,1003'
    select * from tbl1 where col1 in (@x)
    Result - "Syntax error converting the varchar value '1001,1002,1003' to a column of data type int."

    Tbl1.col1 is an int data type. I understand why I'm getting the error but how can I build the select statement so this will work?

    Thanks,

    Jim

Posting Permissions

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