SQL: Convert GUID to UNIQUEIDENTIFIER

Sample for converting GUID to UNIQUEIDENTIFIER

DECLARE @uuid VARCHAR(36),
@guid UNIQUEIDENTIFIER

SET @uuid = '677358dff67845a88dc8287645abe999'
SELECT @guid = CAST(
        SUBSTRING(@uuid, 1, 8) + '-' + SUBSTRING(@uuid, 9, 4) + '-' + SUBSTRING(@uuid, 13, 4) + '-' +
        SUBSTRING(@uuid, 17, 4) + '-' + SUBSTRING(@uuid, 21, 12)
        AS UNIQUEIDENTIFIER)
                         
SELECT [orgDocId] FROM [SomeDB].[dbo].[SomeTable]
  where [orgDocId] = @guid 

The End.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: