Geeks With Blogs

Tim Huffam Dotting the I and crossing the T of I.T.

I got this error (Syntax error converting from a character string to uniqueidentifier.) when trying to run the following SQL insert from within Query Analyser:

insert into [dbo].[TeamUsers] ([TeamId], [UserId], [RoleType]) values (3, 'f7b681c0faeb11d69aed0008c7e6fa6a',2)

Column UserID is a uniqueidentifier.

So I tried it without the quotes:

insert into [dbo].[TeamUsers] ([TeamId], [UserId], [RoleType]) values (3, f7b681c0faeb11d69aed0008c7e6fa6a,2)

.. but got this error:

The name 'f7b681c0faeb11d69aed0008c7e6fa6a' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

The problem, however was not that I needed to convert it from a string or integer to a uniqueidentifier, but rather that I had used an incorrect format.   Instead it should have looked like this (using the standard GUID format) - and be quoted:

insert into [dbo].[TeamUsers] ([TeamId], [UserId], [RoleType]) values (3, 'f7b681c0-faeb-11d6-9aed-0008c7e6fa6a',2)

 

Posted on Tuesday, October 4, 2005 2:40 PM SQL Server | Back to top


Comments on this post: Syntax error converting from a character string to uniqueidentifier.

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
its not possible insert 'f7b681c0faeb11d69aed0008c7e6fa6a'

Uniqueidentifier is auto generated ID

simply set the Is RowGuid "yes" in the enterpricemanager for that field

Left by vijayamirtharaj on Feb 15, 2007 4:03 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
vijayamirtharaj wrote:
> Uniqueidentifier is auto generated ID

No, you are thinking about identity. Uniqueidentifiers are not auto generated. They are guarenteed to be globaly unique.
Left by RoyHeil on Mar 07, 2007 1:03 PM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
UniqueIdentifier is autogenerated if you set default value to (newid()) and do not set the value initially.
Left by MWentzel on Apr 06, 2007 3:05 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
Yes, uniqueidentifier is autogenerated, but you can set it manually as well. I have the same problem when I am running an application using SqlDataSource. At least, this error is not the matter of autogeneration since I was able to insert it.
Left by Jay on Jun 25, 2007 7:20 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
try putting it in the format '{FC85BB30-EE95-4AE2-859A-E0252BA1AAFE}'
Left by akaEdge on Aug 21, 2007 11:16 PM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
UniqueIdentifier is autogenerated if you set default value to (newid()) and do not set the value initially i know this Very Well this is True
Left by Hassan on Sep 23, 2007 11:16 PM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
First.. UniqueIdentifier doesn't need to be auto-generated. You can insert any vlaue you need to.

I wasn't able to get it to work in, but i found doing something like this did work

insert into [dbo].[TeamUsers] ([TeamId], [UserId], [RoleType]) values (3, 'f7b681c0-faeb-11d6-9aed-0008c7e6fa6a',2)

DECLARE @USER_ID uniqueidentifier
SET @USER_ID = CAST( 'f7b681c0-faeb-11d6-9aed-0008c7e6fa6a' as uniqueidentifier )
insert into [dbo].[TeamUsers] ([TeamId], [UserId], [RoleType]) values (3, @USER_ID, 2)
Left by TG on Apr 24, 2008 4:24 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
Thanks TG the Declare syntax worked.
Left by JED on Feb 23, 2009 8:53 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
I am retriving guid from database to grid view and i want to again insert it back into another table how can i do that
Left by vikram babar on Apr 13, 2011 5:13 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
i am getting this error conversion failed when converting character string to uniqueidenfier..i used stored procedure

Any one know pls help me
Left by venkatesan on Jul 05, 2012 1:55 AM

# re: Syntax error converting from a character string to uniqueidentifier.
Requesting Gravatar...
thanks TG, it worked
Left by KAMALJIT on Nov 06, 2012 5:12 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Huffam | Powered by: GeeksWithBlogs.net | Join free