I am trying to solve a problem very similar to Convert from UniqueIdentifier to BigInt and Back? Unfortunately that example doesn't show the whole process, it only shows converting a GUID back to BIGINT.
I'll call this a hypothetical problem since I've already decided that storing integers as GUID's isn't very beneficial. However at this point, I simply want to know why the conversion process isn't working.
Everything looks good until step 5....
SELECT 1 AS Step
,100966116980299
SELECT 2 AS Step
,CONVERT(VARBINARY(8), 100966116980299, 1)
SELECT 3 AS Step
,CONVERT(UNIQUEIDENTIFIER,
CONVERT(VARBINARY(8), 100966116980299, 1)
)
SELECT 4 AS Step
,CONVERT(VARBINARY(8),
CONVERT(UNIQUEIDENTIFIER,
CONVERT(VARBINARY(8), 100966116980299, 1)
), 1
)
SELECT 5 AS Step
,CONVERT(BIGINT,
CONVERT(VARBINARY(8),
CONVERT(UNIQUEIDENTIFIER,
CONVERT(VARBINARY(8), 100966116980299, 1)
), 1
)
)
Results
Step Value
1 100966116980299
2 0x0F0000014B768901
3 0100000F-764B-0189-0000-000000000000
4 0x0F0000014B768901
5 1080863916129945857