Link to home
Start Free TrialLog in
Avatar of robthomas09
robthomas09

asked on

SQL Cast statement error - varchar to uniqueidentifier

Hello all,

I am trying to insert a 36 character string into a test table as shown below, but I still get the famous "Conversion failed when converting from a character string to uniqueidentifier."  Can someone point out the obvious flaw in my query:

create table test3(
id uniqueidentifier
)

declare @id2 varchar(36)
set @id2 = '9D9CB28D-1918-42DB-A7A4-C8A1FC89209Q'

insert into test3
(id)

values(
cast(@id2 as uniqueidentifier)

)

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Bhavesh Shah
Bhavesh Shah
Flag of India 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
Hi,

You have a 'Q' last in the string, that should be an illegal  char.

/peter
SOLUTION
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