Help Syntax error converting the varchar value

  • need help to update

    Server: Msg 245, Level 16, State 1, Line 2

    Syntax error converting the varchar value '1,2,3,4,5' to a column of data type int.

    --------------------------------------------

    DECLARE@na [int], @sisi [int], @mmh [char](10),@exec_start VARCHAR(100)

    set @na ='1,2,3,4,5'

    set @sisi='2'

    SET @mmh='555'

    set @exec_start ='WHERE CONVERT(VARchar(20), [na]) IN ('+@na+')'

    UPDATE [Gibor_h].[dbo].[Sn]

    SET [sisi] = @sisi,

    [mmh] = @mmh

    EXEC (@exec_start)

    -----------------------------

    thnks

    ilan

    Edited by - midan1 on 06/23/2003 6:22:55 PM

    Edited by - midan1 on 06/23/2003 6:26:20 PM

  • I don't believe you can do what you are trying. Commas are not integers. The data you are trying to put into @na is a string, therefore the datatype needs to be char or varchar.

    -SQLBill

  • Also you are trying to misuse EXEC. Is this what you are trying to do?

    DECLARE @na varchar(100), @sisi int, @mmh char(10)

    set @na ='1,2,3,4,5'

    set @sisi='2'

    SET @mmh='555'

    UPDATE [Gibor_h].[dbo].[Sn]

    SET [sisi] = @sisi,

    [mmh] = @mmh

    WHERE charindex(CONVERT(varchar,[na]),','+@na+',') > 0

    Far away is close at hand in the images of elsewhere.
    Anon.

  • The code work 100%

    thnks

    ------

    a another small question ?

    How can i use this code

    but For Multi DELETE

    ---------

    Thnks

    again

    ILAN

  • DECLARE @na varchar(100)

    set @na ='1,2,3,4,5'

    DELETE FROM [Gibor_h].[dbo].[Sn]

    WHERE charindex(','+CONVERT(varchar,[na])+',',','+@na+',') > 0

    Sorry in my last post forgot to put commas around converted na column. Need to do this to make sure data matches correctly (eg ,1, in 1,2,3,4,5) otherwise 1 could be found in 9,10,11. Use the following

    WHERE charindex(','+CONVERT(varchar,[na])+',',','+@na+',') > 0

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Thank you for your help

    ilan

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

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