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)
 Error creating stored proc. uniqueidentifier

Author  Topic 

dwfresh
Starting Member

4 Posts

Posted - 2008-08-05 : 16:58:04
Hi guys
I am getting this pesky error and I don't know why.
Can someone tell me why I'm stuck. Im a newbie so please bear with me :)

Msg 206, Level 16, State 2, Procedure sp_User_Create, Line 21
Operand type clash: uniqueidentifier is incompatible with int


Here is the stored procedure I am trying to create.
I have a Users table. The 'UserId' column is the primary key (int), but I also have a 'Guid' column which is a uniqueidentifier.


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[sp_User_Create]
(@FirstName nvarchar(50),
@LastName nvarchar(50),
@LoginName nvarchar(50),
@EgovUserProfileID int,
@EgovUserToken nvarchar(256),
@SecretQuestionId int,
@SecretAnswer nvarchar(256),
@MothersMaidenName nvarchar(50),
@Ssn nvarchar(9),
@UserId int OUTPUT,
@Guid uniqueidentifier OUTPUT)
AS


BEGIN
IF( @UserId IS NULL )
SELECT @UserId = NEWID()
ELSE
BEGIN
IF( EXISTS( SELECT UserId FROM dbo.Users
WHERE @UserId = UserId ) )
RETURN -1
END

INSERT into dbo.Users (FirstName, LastName, LoginName, Ssn, EgovUserProfileID, EgovUserToken, SecretQuestionId, SecretAnswer, MothersMaidenName, CreateDate, LastLoginDate, Guid)
VALUES (@FirstName, @LastName, LOWER(@LoginName), @Ssn, @EgovUserProfileID, @EgovUserToken, @SecretQuestionId, @SecretAnswer, @MothersMaidenName, GetDate(), Getdate(), newId())

RETURN 0
END

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-05 : 17:13:52
quote:
Originally posted by dwfresh

Hi guys
I am getting this pesky error and I don't know why.
Can someone tell me why I'm stuck. Im a newbie so please bear with me :)

Msg 206, Level 16, State 2, Procedure sp_User_Create, Line 21
Operand type clash: uniqueidentifier is incompatible with int


Here is the stored procedure I am trying to create.
I have a Users table. The 'UserId' column is the primary key (int), but I also have a 'Guid' column which is a uniqueidentifier.


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE [dbo].[sp_User_Create]
(@FirstName nvarchar(50),
@LastName nvarchar(50),
@LoginName nvarchar(50),
@EgovUserProfileID int,
@EgovUserToken nvarchar(256),
@SecretQuestionId int,
@SecretAnswer nvarchar(256),
@MothersMaidenName nvarchar(50),
@Ssn nvarchar(9),
@UserId int OUTPUT,
@Guid uniqueidentifier OUTPUT)
AS


BEGIN
IF( @UserId IS NULL )
SELECT @UserId = NEWID()
ELSE
BEGIN
IF( EXISTS( SELECT UserId FROM dbo.Users
WHERE @UserId = UserId ) )
RETURN -1
END

INSERT into dbo.Users (FirstName, LastName, LoginName, Ssn, EgovUserProfileID, EgovUserToken, SecretQuestionId, SecretAnswer, MothersMaidenName, CreateDate, LastLoginDate, Guid)
VALUES (@FirstName, @LastName, LOWER(@LoginName), @Ssn, @EgovUserProfileID, @EgovUserToken, @SecretQuestionId, @SecretAnswer, @MothersMaidenName, GetDate(), Getdate(), newId())

RETURN 0
END



>>SELECT @UserId = NEWID()

You have declared @userid as an INT. Did you mean "select @guid = newid()" ?

EDITI:
How are new UserIDs created? I guess that is what you are trying to do. Perhaps UserID should be an identity column. And what purpose is the GUID column going to serve?


Be One with the Optimizer
TG
Go to Top of Page

dwfresh
Starting Member

4 Posts

Posted - 2008-08-05 : 17:26:05
ahh yes, thank you.
I use GUIDs for added security and as a truly unique identifier for a user, for cookies, etc.
Go to Top of Page
   

- Advertisement -