SQL Server berhenti cerdas ketika membandingkan nilai yang memiliki tipe data berbeda.
Skrip berikut berfungsi apa adanya tanpa konversi eksplisit
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
Hasil
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