• Register
0 votes
134 views

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'),
   CONVERT(uniqueidentifier,'DF215E10-8BD4-4401-B2DC-99BB03135F2E'),
'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

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..

OR

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

 OR

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.

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

 

9 7 4
38,600 points

Related questions

0 votes
1 answer 312 views
312 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 jwilliam 3.9k points
1 vote
1 answer 38 views
38 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 stewart 4k points
0 votes
1 answer 79 views
79 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 156 views
156 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