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

robthomas09Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale BurrellDirectorCommented:
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.
0
robthomas09Author Commented:
Thanks Dale - I have confirmed that it is a GUID in string form.

Thanks
0
Dale BurrellDirectorCommented:
In that case you code snippet will work.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

robthomas09Author Commented:
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?
0
Dale BurrellDirectorCommented:
As the error says, one or more of your string values is either not a GUID or is not formatted corrected as per my first post. This is common problem when trying to move untyped data to typed data. You need to build some queries to find the bad data and then build you query to correct it. If you take a look a the MSDN reference for the 'LIKE' statement you'll see you can have it match a pattern which should help you to identify those that don't.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robthomas09Author Commented:
I found em- thanks Dale!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.