Link to home
Start Free TrialLog in
Avatar of robthomas09
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!
Convert(uniqueidentifier,column_name_original)

Open in new window

Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

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.
Avatar of robthomas09
robthomas09

ASKER

Thanks Dale - I have confirmed that it is a GUID in string form.

Thanks
In that case you code snippet will work.
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?
ASKER CERTIFIED SOLUTION
Avatar of Dale Burrell
Dale Burrell
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found em- thanks Dale!