Discussion: Conversion failed when converting from a character string to uniqueidentifier. (too old to reply) Using sql 08 I need to convert a string to a uniqueidentifer which is DECLARE -- I tried both guids below and both failed. SET @id = CONVERT(UNIQUEIDENTIFIER, @str); select @id and this code returns this error msg: -- Post by moondaddy Try "SELECT @str". That will give you a revelation. -- Links for SQL Server Books Online: Thanks for the
reply, but that had not effect on the outcome. I stil get Post by Erland Sommarskog Post by
moondaddy -- Post by moondaddy Post by Erland Sommarskog Post by moondaddy -- what was the result when you performed SELECT @str? The revelation you should have had - if you ran the above is that Jeff Thanks that was it. I set the varchar to varchar(50) and it worked. Post by Jeffrey Williams Post by moondaddy Post by Erland Sommarskog Post by moondaddy -- The revelation you should have had - if you ran the above is that Actually, I'm still having trouble. Here's exactly what I have: DECLARE -- run code... CREATE TABLE #Ap_Ids (ID uniqueidentifier) INSERT INTO #Ap_Ids (ID) It errors on the insert statement and when I step through this code here's @tmpSTR '0be3cf11-7daf-4f61-bca2-9797293a79f4' varchar so it seems that I'm doing everything correctly, but I'm still getting the any more ideas? Post by Jeffrey Williams Post by moondaddy Post by Erland Sommarskog Post by moondaddy -- The revelation you should have had - if you ran the above is that Post by moondaddy Yes, I have an idea: post exactly what you are doing, and also post the For the record, this runs without error on my machine: DECLARE @tmpSTR varchar(50) -- Links for SQL Server Books Online: The values you have converts just fine for me, so there is probably DECLARE @tmpSTR varchar(50) = '0be3cf11-7daf-4f61-bca2-9797293a79f4' CREATE TABLE #Ap_Ids (ID uniqueidentifier) INSERT INTO #Ap_Ids (ID) Post by
moondaddy Post by Jeffrey Williams Post by moondaddy Post by Erland Sommarskog Post by moondaddy -- The revelation you should have had - if you ran the above is that Post by moondaddy I forgor to mention that you should actually look at the output. -- Links for SQL Server Books Online: I've seen this error a few times with SQL Server 2008. It's still happening The first time I saw it was when executing statements like this: delete from something where aguid = '230BD1E4-FD9B-4A09-B666-BF4B7BD8F79D' I changed it to this and it worked: delete from something where aguid = The last time I saw it was when executing 100s of pairs of deletes and delete from something where aguid = '230BD1E4-FD9B-4A09-B666-BF4B7BD8F79D' The curious thing is that 100s of pairs of statements worked fine, then all In every case I've seen, an explicit transaction was involved and the If I take the offending statement and execute it by itself, it works just By the way,
CAST is ANSI, CONVERT is SQL Server specific, which is why I John Cook I went back and checked the code for the second test case. I agreed with Loading... |