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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uniqueidentifiers in tsql

Status
Not open for further replies.

iminore

Programmer
Sep 3, 2002
50
GB
when I run:

declare @guid uniqueidentifier
set @guid='{17D679DD-DB5E-41F9-9CCA-915A56624A32}'
exec('select * from profile where guid=' + @guid)

I get the message:

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'D679DD'.

when I run:

declare @guid uniqueidentifier
set @guid='{17D679DD-DB5E-41F9-9CCA-915A56624A32}'
exec('select * from profile where guid=' + cast(@guid as varchar(255)))

I get the message:

Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near 'cast'.

Just what are the rules for using uniqueidentifiers in tsql.

I want to use exec because I want the database name to be a parameter.
 
as far as the second error message is concerned, you can't use a CAST function inside a EXEC statement

try this instead



declare @guid uniqueidentifier

declare @strSQL varchar(1000)

set @guid='{17D679DD-DB5E-41F9-9CCA-915A56624A32}'

set @strSQL ='select * from profile where guid=' + cast(@guid as varchar(255))
exec(@strSQL)


Hope this helps
LFCfan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top