Skip to content
Advertisement

Insert row with uniqueidentifier

This is a snippet from a stored proc that creates a database. We have a table with uniqueidentifier PK. I’m trying to insert a row with an empty guid as the PK:

The error messages are

Can’t see what’s wrong with the VALUES clause but I guess it has something to do with the final quote, although the final quote is a closing quote not an opening quote. Maybe it’s the way I assign the empty guid to @MailingListId? Should @MailingListId be quoted?

Advertisement

Answer

You should be using QUOTENAME for the database name, and proper parameters via sp_executesql. You can also shorten the empty guid to CAST(0x0 AS uniqueidentifier)

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement