SQL Server е доста интелигентен, когато става въпрос за сравняване на стойности с различни типове данни.
Следващият скрипт работи както е, без изрично преобразуване
DECLARE @TableA TABLE (VARCHARID VARCHAR(48) PRIMARY KEY)
DECLARE @TableB TABLE (GUIDID UNIQUEIDENTIFIER PRIMARY KEY)
INSERT INTO @TableA VALUES
('{0CAF3FBC-3C76-420B-B0C4-42867551E3B5}')
, ('{0CAF3FBC-3C76-420B-B0C4-42867551E3B6}')
, ( '0CAF3FBC-3C76-420B-B0C4-42867551E3B7' )
, ( '0CAF3FBC-3C76-420B-B0C4-42867551E3B8' )
INSERT INTO @TableB VALUES
('{0CAF3FBC-3C76-420B-B0C4-42867551E3B5}')
, ( '0CAF3FBC-3C76-420B-B0C4-42867551E3B6' )
, ('{0CAF3FBC-3C76-420B-B0C4-42867551E3B7}')
, ( '0CAF3FBC-3C76-420B-B0C4-42867551E3B8' )
SELECT *
FROM @TableA a
INNER JOIN @TableB b ON b.GUIDID = a.VARCHARID
Резултат
VARCHARID GUIDID
{0CAF3FBC-3C76-420B-B0C4-42867551E3B5} 0CAF3FBC-3C76-420B-B0C4-42867551E3B5
{0CAF3FBC-3C76-420B-B0C4-42867551E3B6} 0CAF3FBC-3C76-420B-B0C4-42867551E3B6
0CAF3FBC-3C76-420B-B0C4-42867551E3B7 0CAF3FBC-3C76-420B-B0C4-42867551E3B7
0CAF3FBC-3C76-420B-B0C4-42867551E3B8 0CAF3FBC-3C76-420B-B0C4-42867551E3B8