robthomas09
asked on
SQL Syntax - Error Converting character String to a unique Identifier
Hi there, I am trying to copy a column in a table to another column, but the source column is a varchar(50) and the destination column is a unique identifier. Of course, I routinely get the error that:
Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.
Can I convert this somehow?
Thanks!
Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.
Can I convert this somehow?
Thanks!
Convert(uniqueidentifier,column_name_original)
You can only convert it if it really is a GUID in string form. You can find out the format it must be in by running 'select convert(varchar(38),newid( ))'. If you can't express your existing string in that exact format you'll need to find another solution.
ASKER
Thanks Dale - I have confirmed that it is a GUID in string form.
Thanks
Thanks
In that case you code snippet will work.
ASKER
Well maybe I spoke too soon - I still receive the error when I try this:
SELECT CAST(src_patient_id AS UNIQUEIDENTIFIER)
from ncs_conv_GENappt_recalls
Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.
Thoughts?
SELECT CAST(src_patient_id AS UNIQUEIDENTIFIER)
from ncs_conv_GENappt_recalls
Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.
Thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found em- thanks Dale!