Converstion Issue from varchar to data int

  • Hi ,

    I am also having problem , i am using a store proc below :

    CREATE PROC dbo.testingloop

    (

    DECLARE @testid varchar(max)

    )

    AS

    BEGIN

    SET NOCOUNT ON

    DECLARE @sql varchar(600)

    SET @testvalue = CURSOR FOR

    SELECT [test ID]) FROM Data42 where [test ID] = 36

    OPEN @testvalue

    FETCH NEXT

    FROM @testvalue INTO @testid

    WHILE @@FETCH_STATUS = 0

    BEGIN

    ' My update statement here

    END

    END

    but i am getting error where there is a [test id] value 12345 - 5 , actually in Data42 table the type of [test id] is nvarchar and in my updating table is varchar , but i think the error is at line 'SET @testvalue = CURSOR FOR

    My Error Message 'Conversion failed when converting the varchar value '12345-2' to data type int.'

  • Hi,

    We met again 🙂

    Update your Procedure as:

    CREATE PROC dbo.testingloop

    (

    DECLARE @testid varchar(max)

    )

    AS

    BEGIN

    SET NOCOUNT ON

    DECLARE @sql varchar(600)

    SET @testvalue = CURSOR FOR

    SELECT [test ID]) FROM Data42 where [test ID] = ‘36’

    OPEN @testvalue

    FETCH NEXT FROM @testvalue INTO @testid

    WHILE @@FETCH_STATUS = 0

    BEGIN

    ' My update statement here

    END

    END

    Thanks,

    Tejas

    www.sqlyoga.com

    Tejas Shah

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

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