Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uniqueidentifier problems

Status
Not open for further replies.

mrrrl

MIS
Joined
Dec 26, 2001
Messages
179
Location
US
I pull data from a sql db table which has two uniqueidentifier one which is key. One is customer_id and the other image_id (key).

customer_id may be the same as others in the table, but image_id will be new and unique data.

When I go to do an insert back into the db table and I get the following error:

Syntax error converting from a character string to uniqueidentifier

How do I pull the customer_id field from the table and keep it from converting into a string or how do I convert it back into a uniqueindentifier format so I can put it back into the table?

And

How do I format a new image_id to put into the table?

TIA
 
Probably the easiest way to create a new GUID is on the server side. If you have access to the table itself you could set the default for image_id to newid() (sql server function). Then you just don't specifiy that column on an insert and the database creates a new GUID value that is valid, for the column.

As far as inserting on the user_id- what method are you using for the query? You may want to look at what is being sent to the database. The examples in SQL books on line for GUID constants are

character format
'6F9619FF-8B86-D011-B42D-00C04FC964FF'

which looks like you just use single quotes- like other character stuff, dates, etc.

and the binary format
0xff19966f868b11d0b42d00c04fc964ff

which looks like it goes in w/out any quotes around it or anything- like if you were inserting a number. (well not 'like', that is what is happening)

This question kind of crosses over 2 topics- VB and SQL Server. The info. here is for the SQL Server side but if you could post what the code looks like- there may be things to consider on that side as well.

Hope that helps,
Ron
 
"Probably the easiest way to create a new GUID is on the server side. If you have access to the table itself you could set the default for image_id to newid() (sql server function). Then you just don't specifiy that column on an insert and the database creates a new GUID value that is valid, for the column."

I can't change the table itself. I tried to skip that column on the Insert command, but I just get another error.

"if you could post what the code looks like"

Nothing special about the code, I am just using a standard SQL Insert command.

I just pull customer_id from one table and insert it into another table. I have some code that generates the image_id data in the GUID format (6F9619FF-8B86-D011-B42D-00C04FC964FF) and I just need to insert this also.
 
wrap the guid in single quotes like he said. The engine will convert it. Make sure you trim it though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top