简体   繁体   中英

Error executing stored procedure with uniqueidentifier input parameter

When I execute the stored procedure that has the first input parameter of type uniqueidentifier which is the primary key column in a table that inserts the values into, it is throwing the below error. I couldn't find whats wrong with this input or stored procedure.

EXEC    @return_value = DbInsert
        @id =   EX642793-385D-604F-BE81-0000CD376836,
        @name= N'000001_067_0xed642993385d604fbe810000cd376836.tif',
        @image = 0x49492A00080000001300FE00040001000000020000000001040001000000C50900000101040001000000E90D0000020103000

SELECT  'Return Value' = @return_value

My stored procedure:

CREATE PROCEDURE DbInsert
    @id UNIQUEIDENTIFIER,
    @name VARCHAR(255),
    @image IMAGE
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO TbImage (Id, Name, Image )
    VALUES (@id, @name, @image)
END

Error:

Msg 102, Level 15, State 1, Line 7
Incorrect syntax near '-'.

Update

I tried to right click the stored procedure and execute, and it didn't ask me for quote and all, but the query I wrote above is what it shown as error. When I try with quote, it throw below error

Msg 8114, Level 16, State 1, Procedure DbInsert, Line 0 [Batch Start Line 2]
Error converting data type varchar to uniqueidentifier. (1 row(s) affected)

Update again

Using valid Uniqueidentifier by changing some numbers myself, however replaced X with some other char...still no luck.

EM662993-385D-604F-BE81-0000CD376838

There are 2 issues with your code:

  1. You need to single quote uniqueidentifiers eg 'DE5AA552-0601-453C-AF21-9B285FA4E920' .

  2. A guid/uniqueidentifier must contain only valid hexidecimal characters, and X is not a valid hexidecimal character and is therefore not valid within a uniqueidentifier so 'EX642793-385D-604F-BE81-0000CD376836' is not valid but 'EA642793-385D-604F-BE81-0000CD376836' is. You can use http://guid.us/Test/GUID to verify and generate guids.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM