Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring a Variable as a Unique identifier is not working fine

I have written a simple SQL query where I declare a variable as an UNIQUEIDENTIFIER type, and I am trying to insert that into a table where the column is of UNIQUEIDENTIFIER type. But I get an error message saying

Conversion failed when converting from a character string to uniqueidentifier.

Can anyone help me with this?

Here's my code:

DECLARE @SessionId AS UNIQUEIDENTIFIER;
SET @SessionId='G51F4E30-E1AB-4E7E-8F5B-0E2613DC9001';

PRINT @SessionId;

INSERT INTO [DB_Name].[dbo].[table_name] ([SessionId])
VALUES (@SessionId);
like image 964
Arvind Avatar asked Mar 22 '23 15:03

Arvind


1 Answers

SET @SessionId='G51F4E30-E1AB-4E7E-8F5B-0E2613DC9001';
                ^

'G' is not a valid hexadecimal character. GUIDs can only consist of characters from 0-9 and A-F.

like image 82
Adrian Wragg Avatar answered Mar 25 '23 19:03

Adrian Wragg