• 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 453 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
1 vote
1 answer 89 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 106 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
2 answers 201 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
1 vote
1 answer 20 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
0 votes
1 answer 6 views
I received an error message when converting data type varchar to numeric I imported data into VARCHAR column to check correct character types before moving into the destination table. I ran across some decimal values they could not CAST or CONVERT even though they ... values. I received the message "Error converting data type varchar to numeric.” How can I load these problems values?
asked Nov 24, 2020 miki 1.9k points
0 votes
1 answer 47 views
Problem : I was getting the following error when running a SQL the conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 104 views
Problem : I am getting bellow error related to datetime the conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
asked Nov 7, 2019 peterlaw 6.9k points
0 votes
1 answer 3 views
I’m getting error converting data type varchar to numeric sql, how can I solve it?
asked Dec 7, 2020 TeamScript 9.5k points