SELECT CASE
WHEN {{ Parameter }} = "Label Column 1" THEN COLUMN_1
WHEN {{ Parameter }} = "Label Column 2" THEN COLUMN_2
ELSE COLUMN_3
END
FROM MY_TABLE
WHERE ...;
DECLARE @SQL VARCHAR(MAX)
SELECT @SQL='SELECT CASE
WHEN '+CAST(@PARAMETER AS varchar(50))+' = ''Label Column 1'' THEN COLUMN_1
WHEN '+CAST(@PARAMETER AS varchar(50))+' = ''Label Column 2'' THEN COLUMN_2
ELSE COLUMN_3
END
FROM MY_TABLE
WHERE ...;'
EXECUTE SP_EXECUTESQL @SQL
1条答案
按热度按时间brc7rcf01#
您可以在SQL Server中尝试以下操作: