• Register
0 votes

Problem :

I don't understand why I am unable to insert this. I can't spot any problem. The error message is as below :

Conversion failed when converting from a character string to uniqueidentifier.

A GUIDs are the ones that I got when I did the select from some other tables.

insert into [db].[dbo].[table] (myid,friendid,time1,time2) values
 ( CONVERT(uniqueidentifier,'0C6A36BA-10E4-438F-BA86-0D5B68A2BB15'),
'2014-01-05 02:04:41.953','2014-01-05 12:04:41.953')

I use the SQL Server 2012

The columns are as below

id        uniqueidentifier,
myid      uniqueidentifier,
friendid  uniqueidentifier,
time1     datetime nullable,
time2     datetime nullable


7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The problem was that your ID column wasn't getting any value. I saw on the SQL Fiddle that you declared the ID column with DEFAULT newid and I didn't..


MSDN Documentation for you Here

To add a bit you can convert a string to a uniqueidentifier using a following code

SELECT CONVERT(uniqueidentifier,'DF215E10-8BD4-4401-B2DC-99BB03135F2E')

If that doesn't work check to make sure that you have entered the valid GUID


I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the very common problem with the people getting started.

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


9 7 4
38,600 points

Related questions

0 votes
1 answer 570 views
Problem : I have the table storing starttime and endtime. I am facing below error: “Conversion failed when converting character string to smalldatetime data type.” While selecting the below query using that table. select CAST(substring(CONVERT(varchar,convert(smalldatetime,o. ... face any error. But, when I select it from a table I got the error. Can somebody help me with this?
asked Jan 20, 2020 jwilliam 3.9k points
0 votes
1 answer 2 views
Problem: Conversion failed when converting the nvarchar value 'test' to data type int.How can I get solution of this?
asked 3 days ago sumaiya simi 16.2k points
1 vote
1 answer 162 views
Problem : My task is to send email with the file attachments also this attachment must come from the image type data field. If I try to run the below code in both the query window and the stored procedure but my email was not sent and in the query window I can only see ... = 1,     @query_no_truncate = 1; I need to send email but still unable to do so. I am looking for help in fixing the issue.
asked May 6, 2020 stewart 4k points
0 votes
1 answer 162 views
Problem : I am facing following error with the below query in SQL Server 2012. An expression of non-boolean type specified in a context where a condition is expected, near 'RETURN'. SQL Query: CREATE FUNCTION [dbo].[GetMYPMResources](@UserResourceNo ... JOIN JobTask t ON t.JobTaskNo = m.JobTaskNo WHERE t.TaskManagerNo = @UserResourceNo OR t.AlternateTaskManagerNo = @UserResourceNo ) RETURN END
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 2 views
Problem: sql server management studio export to csv.
asked 4 days ago Dan phillip 4.8k points
0 votes
1 answer 4 views
Problem: How to select a partial of a table for exporting using SQL? How can I do that? Thanks
asked Mar 9 ummesalma 25.2k points
0 votes
2 answers 260 views
Problem : I want to access my hosting server’s database through SQL Server Management Studio, everything is fine but when I use the following command use myDatabase it gives me following error: The server principal "****" is not able to access the database "****" under the current security context. Can anyone give me solution on my problem?
asked Nov 21, 2019 peterlaw 6.9k points
0 votes
1 answer 27 views
Problem: system.componentmodel.win32exception: the network path was not found.
asked Feb 12 Shovo210 14k points
1 vote
1 answer 37 views
Problem : I am new to SQL. While trying to execute my JOIN query I am facing below strange error. “Conversion failed when converting the varchar value to data type int”. I am unable to figure out why am I getting above error. Can someone help me in fixing the error?
asked Mar 27, 2020 morrisBson 3.2k points