Solved

SQL Cast statement error - varchar to uniqueidentifier

Posted on 2010-08-25
3
1,051 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
ID: 33524774
0
 
LVL 22

Expert Comment

by:pivar
ID: 33524782
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
ID: 33524953
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 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