GUID Compatiable Id from an Integer

vsslasd 556 Reputation points
2023-04-20T19:43:26.3466667+00:00

Hello,
We need to convert an integer column in a view to a deterministic GUID with the output of that column compatible to link to a GUID type column.

We have tried: Select CalcGUID=Cast(convert(varchar(38),C.Dex_RowID) AS UNIQUEIDENTIFIER)_ From table1 _
(C.Dex_RowID is an integer column)

The above syntax fails when trying to run the view with the following message:

Msg 8169, Level 16, State 2, Line 1 Conversion failed when converting from a character string to uniqueidentifier.

How can we convert an integer column in a view to have a GUID column type?

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-04-21T02:04:06.9933333+00:00

    Hi @vsslasd

    You can try the conversion method mentioned in this thread.

    https://stackoverflow.com/questions/19656213/different-casting-of-int-to-guid-in-c-sharp-and-sql-server

    Best regards,

    Percy Tang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.