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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem with stored procedure parameters

Author  Topic 

theonlylawislove
Starting Member

7 Posts

Posted - 2008-03-17 : 03:23:38
I'm executing a stored procedure with a parameter that is a uniqueidentifier or guid(vb).

When I then try to insert that value into a table, I get the following error....

Incorrect syntax near '-'.

ALTER PROCEDURE [dbo].[mw_Articles_UpdateArticle]
-- Add the parameters for the stored procedure here
@ArticleID INT,
@Title VARCHAR(50),
@Body VARCHAR(MAX),
@ParentID INT,
@UserName NVARCHAR(256) = NULL,
@UserID uniqueidentifier = NULL,
@Importance INT,
@Approved BIT,
@EditNotes VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

IF EXISTS(SELECT ArticleID FROM mw_Articles WHERE ArticleID = @ArticleID)
BEGIN
PRINT 'FOUND'
DECLARE @CurrentVersion INT
SELECT @CurrentVersion = (SELECT MAX(Version) FROM mw_ArticlesVersions WHERE ArticleID = @ArticleID)
INSERT INTO mw_ArticlesVersions(ArticleID, Version, Title, Body, ParentID, Approved, UserName, UserID, Importance, EditNotes) VALUES (@ArticleID, @CurrentVersion + 1, @Title, @Body, @ParentID, @Approved, @UserName, @UserID, @Importance, @EditNotes)
IF @Approved = 1
BEGIN
UPDATE mw_Articles SET Version = (@CurrentVersion + 1) WHERE ArticleID = @ArticleID
END
END
ELSE
BEGIN
PRINT 'NOT FOUND'
END


END



EXEC @return_value = [dbo].[mw_Articles_UpdateArticle]
@ArticleID = 20,
@Title = N'roooot',
@Body = N'dfgh',
@ParentID = 0,
@UserName = N'1',
@UserID = 66116249-63da-4179-85b4-08fd2fa6a315,
@Importance = sdfg,
@Approved = 1,
@EditNotes = N'sdfg'

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-17 : 04:54:19
[code]EXEC @return_value = [dbo].[mw_Articles_UpdateArticle]
@ArticleID = 20,
@Title = N'roooot',
@Body = N'dfgh',
@ParentID = 0,
@UserName = N'1',
@UserID = '66116249-63da-4179-85b4-08fd2fa6a315',
@Importance = sdfg,
@Approved = 1,
@EditNotes = N'sdfg'
[/code]

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

theonlylawislove
Starting Member

7 Posts

Posted - 2008-03-17 : 11:57:39
Just the 's?

I was testing the stored procedure with the contextmenu-executestoredprocedure, and I pasted the guid value from my clipboard.

Are you saying that when I enter the guid, I should as '' around it?

Why doesn't sql server take care of this?
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-03-17 : 19:55:07
quote:
Originally posted by theonlylawislove


Why doesn't sql server take care of this?


Er, because how would it know when the string ends? It doesn't know that the comma after your guid is not part of the string, nor the newline, nor the @Importance. The world does not revolve around your specific case!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-18 : 02:50:34
<<
Are you saying that when I enter the guid, I should as '' around it?
>>

Yes

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jchiking
Starting Member

1 Post

Posted - 2008-03-20 : 11:18:52
Er, because how would it know when the string ends? It doesn't know that the comma after your guid is not part of the string, nor the newline, nor the @Importance. The world does not revolve around your specific case!

In regards to this comment, it has nothing to do with revolving around him. I am seeing a similar problem. From C# code, I create a System.Guid instance, pass this to a stored procedure that accepts a uniqueidentifier, which then uses the value in a Select statement. Why should I have to put '' around anything? It seems as if you have to convert it to an nvarchar, or some other sql string datatype. The question is... Is sql converting it? and if so, why the problem with the single quotes?
Go to Top of Page
   

- Advertisement -