'Operand type clash: numeric is incompatible with uniqueiden

  • #1
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.
 

Answers and Replies

  • #2
Samy_A
Science Advisor
Homework Helper
1,241
510
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 SlurrerOfSpeech

Related Threads on 'Operand type clash: numeric is incompatible with uniqueiden

Replies
10
Views
807
Replies
4
Views
2K
Replies
3
Views
727
  • Last Post
Replies
8
Views
5K
Replies
4
Views
1K
  • Last Post
Replies
2
Views
793
Replies
3
Views
1K
  • Last Post
Replies
8
Views
1K
Replies
5
Views
2K
Top