Solved

SQL Cast statement error - varchar to uniqueidentifier

Posted on 2010-08-25
3
1,047 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:robthomas09
3 Comments
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 300 total points
Comment Utility
0
 
LVL 22

Expert Comment

by:pivar
Comment Utility
Hi,

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

/peter
0
 
LVL 16

Assisted Solution

by:vdr1620
vdr1620 earned 200 total points
Comment Utility
Try the below Sample query..there are no flaws in the Syntax nor the query..Its just that SQL is not able to convert the string into a unique identifier


create table #test3(

id uniqueidentifier

)



declare @id2 varchar(36)

set @id2 = '6F9619FF-8B86-D011-B42D-00C04FC964FF'



insert into #test3

(id)



values(

cast(@id2 as uniqueidentifier)



)

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now