Home Forums SQL Server 2008 T-SQL (SS2K8) Conversion failed when converting from a character string to uniqueidentifier. RE: Conversion failed when converting from a character string to uniqueidentifier.

  • The problem is because you have a list of numbers and you are trying to compare that to a uniqueidentifier.

    You insert this into a table.

    ('101038, 101039, 101040, 101044')

    INSERT INTO @Tmp (JobIds)

    SELECT CAST(Items AS VARCHAR(40)) FROM InterfaceSystem.dbo.fn_SplitString(@jobid,',')

    But then you try to find them in your table. Assuming itt_jobcodeid is a uniqueidentifier you are comparing apples to oranges here. It will attempt to cast your values to a uniqueidentifier and those are not valid values.

    and i.itt_jobcodeid in (select JobIDs from @Tmp)

    As a side note, I would highly recommend reading the article linked in my signature about splitting strings. It will blow the doors off the while loop splitter.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/