Tim Huffam

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

  Home  |   Contact  |   Syndication    |   Login
  153 Posts | 0 Stories | 2747 Comments | 653 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

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

Feedback

# re: Syntax error converting from a character string to uniqueidentifier. 2/15/2007 4:03 AM vijayamirtharaj
its not possible insert 'f7b681c0faeb11d69aed0008c7e6fa6a'

Uniqueidentifier is auto generated ID

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



# re: Syntax error converting from a character string to uniqueidentifier. 3/7/2007 1:03 PM RoyHeil
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.

# re: Syntax error converting from a character string to uniqueidentifier. 4/6/2007 3:05 AM MWentzel
UniqueIdentifier is autogenerated if you set default value to (newid()) and do not set the value initially.

# re: Syntax error converting from a character string to uniqueidentifier. 6/25/2007 7:20 AM Jay
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.

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

# re: Syntax error converting from a character string to uniqueidentifier. 9/23/2007 11:16 PM Hassan
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

# re: Syntax error converting from a character string to uniqueidentifier. 4/24/2008 4:24 AM TG
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)

# re: Syntax error converting from a character string to uniqueidentifier. 2/23/2009 8:53 AM JED
Thanks TG the Declare syntax worked.

# re: Syntax error converting from a character string to uniqueidentifier. 4/13/2011 5:13 AM vikram babar
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

# re: Syntax error converting from a character string to uniqueidentifier. 7/5/2012 1:55 AM venkatesan
i am getting this error conversion failed when converting character string to uniqueidenfier..i used stored procedure

Any one know pls help me

# re: Syntax error converting from a character string to uniqueidentifier. 11/6/2012 5:12 AM KAMALJIT
thanks TG, it worked

Post A Comment
Title:
Name:
Email:
Comment:
Verification: