'Operand type clash: numeric is incompatible with uniqueiden

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
SlurrerOfSpeech
Messages
141
Reaction score
11
Could use some help figuring out the error

Operand type clash: numeric is incompatible with uniqueidentifier

which points to the specified line below

Code:
CREATE PROCEDURE AddPartner 
    @name NVARCHAR(50), @email NVARCHAR(254), @new_guid UNIQUEIDENTIFIER OUTPUT
AS
BEGIN
    SET NOCOUNT ON 
    INSERT INTO Partners (name,email) VALUES (@name,@email)
    SELECT @new_guid = SCOPE_IDENTITY() -- specified line
    RETURN
END

The table Partners is of the form

Code:
CREATE TABLE Partners ( 
    id UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
    name NVARCHAR(50) NOT NULL,
    email NVARCHAR(254) NOT NULL, -- 254 is optimal length according to http://stackoverflow.com/questions/1199190/what-is-the-optimal-length-for-an-email-address-in-a-database
    PRIMARY KEY (id)
);

Any help in figuring out this error? What I'm trying to do is return from the procedure the guid that was just assigned to the row that was just inserted.
 
Physics news on Phys.org
SlurrerOfSpeech said:
Could use some help figuring out the error

Operand type clash: numeric is incompatible with uniqueidentifier

which points to the specified line below

Code:
CREATE PROCEDURE AddPartner
    @name NVARCHAR(50), @email NVARCHAR(254), @new_guid UNIQUEIDENTIFIER OUTPUT
AS
BEGIN
    SET NOCOUNT ON
    INSERT INTO Partners (name,email) VALUES (@name,@email)
    SELECT @new_guid = SCOPE_IDENTITY() -- specified line
    RETURN
END

The table Partners is of the form

Code:
CREATE TABLE Partners (
    id UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
    name NVARCHAR(50) NOT NULL,
    email NVARCHAR(254) NOT NULL, -- 254 is optimal length according to http://stackoverflow.com/questions/1199190/what-is-the-optimal-length-for-an-email-address-in-a-database
    PRIMARY KEY (id)
);

Any help in figuring out this error? What I'm trying to do is return from the procedure the guid that was just assigned to the row that was just inserted.
SCOPE_IDENTITY() doesn't work with guid fields.

Here they show how you could get the last inserted guid (haven't tested it).
 
  • Like
Likes   Reactions: SlurrerOfSpeech