Berikan nama kolom sebagai parameter
DECLARE @COLS NVARCHAR(MAX)
DECLARE @TABLE NVARCHAR(MAX)
SET @COLS = 'COL1,COL2'
SET @TABLE = 'TABLENAME'
Sekarang jalankan kueri
DECLARE @QRY NVARCHAR(MAX)
SET @QRY = 'SELECT (SELECT '[email protected]+' FROM '[email protected]+') FROM sourcetable'
EXEC SP_EXECUTESQL @QRY