Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
Asked By: Simon Edström
Originally Asked On: 2014-01-05 23:02:52
Asked Via: stackoverflow
I don’t understand why I can’t insert this. I can’t spot the problem. The error message is
Conversion failed when converting from a character string to uniqueidentifier.The GUIDs are the ones that I got when I did a select from some other tables.
insert into [db].[dbo].[table] (myid,friendid,time1,time2) values ( CONVERT(uniqueidentifier,'0C6A36BA-10E4-438F-BA86-0D5B68A2BB15'), CONVERT(uniqueidentifier,'DF215E10-8BD4-4401-B2DC-99BB03135F2E'), '2014-01-05 02:04:41.953','2014-01-05 12:04:41.953')
I use SQL Server 2012
The columns are
id uniqueidentifier, myid uniqueidentifier, friendid uniqueidentifier, time1 datetime nullable, time2 datetime nullable
He received 3 answers
eventually accepting:
Simon Edström’s answer to
Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
The problem was that the ID column wasn’t getting any value. I saw on @Martin Smith SQL Fiddle that he declared the ID column with
DEFAULT newid
and I didn’t..
The answer with the highest score with 5 points was:
M.Ali’s answer to
Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
DECLARE @t TABLE (ID UNIQUEIDENTIFIER DEFAULT NEWID(),myid UNIQUEIDENTIFIER , friendid UNIQUEIDENTIFIER, time1 Datetime, time2 Datetime) insert into @t (myid,friendid,time1,time2) values ( CONVERT(uniqueidentifier,'0C6A36BA-10E4-438F-BA86-0D5B68A2BB15'), CONVERT(uniqueidentifier,'DF215E10-8BD4-4401-B2DC-99BB03135F2E'), '2014-01-05 02:04:41.953','2014-01-05 12:04:41.953') SELECT * FROM @t
Result Set With out any errors
╔══════════════════════════════════════╦══════════════════════════════════════╦══════════════════════════════════════╦═════════════════════════╦═════════════════════════╗ ║ ID ║ myid ║ friendid ║ time1 ║ time2 ║ ╠══════════════════════════════════════╬══════════════════════════════════════╬══════════════════════════════════════╬═════════════════════════╬═════════════════════════╣ ║ CF628202-33F3-49CF-8828-CB2D93C69675 ║ 0C6A36BA-10E4-438F-BA86-0D5B68A2BB15 ║ DF215E10-8BD4-4401-B2DC-99BB03135F2E ║ 2014-01-05 02:04:41.953 ║ 2014-01-05 12:04:41.953 ║ ╚══════════════════════════════════════╩══════════════════════════════════════╩══════════════════════════════════════╩═════════════════════════╩═════════════════════════╝
If the selected answer did not help you out, the other answers might!
All Answers For: Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
Simon Edström’s answer to
Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
The problem was that the ID column wasn’t getting any value. I saw on @Martin Smith SQL Fiddle that he declared the ID column with
DEFAULT newid
and I didn’t..
M.Ali’s answer to
Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
DECLARE @t TABLE (ID UNIQUEIDENTIFIER DEFAULT NEWID(),myid UNIQUEIDENTIFIER , friendid UNIQUEIDENTIFIER, time1 Datetime, time2 Datetime) insert into @t (myid,friendid,time1,time2) values ( CONVERT(uniqueidentifier,'0C6A36BA-10E4-438F-BA86-0D5B68A2BB15'), CONVERT(uniqueidentifier,'DF215E10-8BD4-4401-B2DC-99BB03135F2E'), '2014-01-05 02:04:41.953','2014-01-05 12:04:41.953') SELECT * FROM @t
Result Set With out any errors
╔══════════════════════════════════════╦══════════════════════════════════════╦══════════════════════════════════════╦═════════════════════════╦═════════════════════════╗ ║ ID ║ myid ║ friendid ║ time1 ║ time2 ║ ╠══════════════════════════════════════╬══════════════════════════════════════╬══════════════════════════════════════╬═════════════════════════╬═════════════════════════╣ ║ CF628202-33F3-49CF-8828-CB2D93C69675 ║ 0C6A36BA-10E4-438F-BA86-0D5B68A2BB15 ║ DF215E10-8BD4-4401-B2DC-99BB03135F2E ║ 2014-01-05 02:04:41.953 ║ 2014-01-05 12:04:41.953 ║ ╚══════════════════════════════════════╩══════════════════════════════════════╩══════════════════════════════════════╩═════════════════════════╩═════════════════════════╝
Logical’s answer to
Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
Ensure that the Column you are Converting OR Casting do not contain BLANK ” Values.
Of course, you should really check out the original question.
The post Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs [ANSWERED] appeared first on Tech ABC to XYZ.