2

I am trying to import a table into SQL Server and executing the following statement:

INSERT INTO [schemes] 
VALUES('3510C197C4043E419C8F01E0C62FA978', 1, 'AS2', null, 
       '2009-04-21 12:52:00.000', '2009-04-21 12:52:00.000');

I am getting an exception

Conversion failed when converting from a character string to uniqueidentifier

Can anyone help me solve this issue?

Mukund
  • 1,679
  • 1
  • 11
  • 20

1 Answers1

2

Try to convert it on a UNIQUEIDENTIFIER in the right format, for sample:

DECLARE @uuid VARCHAR(50)
DECLARE @gid UNIQUEIDENTIFIER

SET @uuid = '3510C197C4043E419C8F01E0C62FA978'
SELECT @gid = CAST(
        SUBSTRING(@uuid, 1, 8) + '-' + SUBSTRING(@uuid, 9, 4) + '-' + SUBSTRING(@uuid, 13, 4) + '-' +
        SUBSTRING(@uuid, 17, 4) + '-' + SUBSTRING(@uuid, 21, 12)
        AS UNIQUEIDENTIFIER)

and after it, insert this value

insert into [schemes] 
values(@gid, 1, 'AS2', null, '2009-04-21 12:52:00.000', '2009-04-21 12:52:00.000');
Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194