Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello,I have a table where the primary key is FAQId which is a GUID.My Procedure has a parameter named @FAQId.I want to check if the is a record in the table where FAQId = @FAQIdHere is the important part of my code:-- Find record with given FAQIdSELECT FAQId FROM dbo.by27_FAQ WHERE FAQId = @FAQId -- Check if FAQId is Null IF FAQId IS NULL BEGIN -- Create a new FAQId by defining a new GUID SET FAQId = NEWID(); -- Insert new FAQ in by27_FAQ INSERT dbo.tFAQ (FAQId, FAQType) VALUES (FAQId, @FAQType)I am getting the error "Incorrect Syntax near =" on code line SET FAQId = NEWID();Any idea what might be going on?Thanks,Miguel
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts
Posted - 2006-12-20 : 22:23:40
Because FAQId is not a variable so that you can directly assign to it.
if not exists(SELECT * FROM dbo.by27_FAQ WHERE FAQId = @FAQId)begin insert dbo.tFAQ (FAQId, FAQType) Values(NEWID(),@FAQType)end
Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-12-21 : 00:56:18
@FAQid variable might be an OUT parameter.
if @faqid is nullbegin select @faqid = newid() insert dbo.tFAQ (FAQId, FAQType) Values(@faqid,@FAQType)endelse if not exists(SELECT * FROM dbo.by27_FAQ WHERE FAQId = @FAQId)begin insert dbo.tFAQ (FAQId, FAQType) Values(@faqid,@FAQType)end
Peter LarssonHelsingborg, Sweden
afrika
Master Smack Fu Yak Hacker
2706 Posts
Posted - 2006-12-21 : 00:57:53
If you want FAQid to be a GUID, change 1. The datatype to be a GUID2. property settings in your table to be newid()It should work