Sql-Server
依賴 T-SQL 比較排序規則
有沒有辦法根據自變數或列值設置字元串比較的排序規則?類似於
SELECT COL1, col2 FROM [TABLE] WHERE COL3 LIKE '%string%' COLLATE CASE CASE_SENSITIVE WHEN 1 THEN SQL_Latin1_General_CP1_CS_AS ELSE SQL_Latin1_General_CP1_CI_AS END
要麼
DECLARE @collation AS VARCHAR(50) SET @collation = 'SQL_Latin1_General_CP1_CI_AS' SELECT COL1, col2 FROM [TABLE] WHERE COL3 LIKE '%string%' COLLATE @collation
沿著這條線,有 2 個 where 條件。
一個將成為
'%string%' LIKE '%string%'
永遠真實的人WHERE CASE WHEN @casesenstive = 1 THEN COL3 ELSE '%string%' END COLLATE SQL_Latin1_General_CP1_CS_AS LIKE '%string%' AND CASE WHEN @casesenstive = 0 THEN COL3 ELSE '%string%' END COLLATE SQL_Latin1_General_CP1_CI_AS LIKE '%string%'