Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

COALESCE to replace multiple CASE statements

$
0
0
Hello Guys, I have a query with huge number of case statements. Basically I need to short this query with getting rid of these hundreds of CASE statements. because of the nature of the application I am not allowed to use a function, and just wondering if there is a possible way to rewrite this with COALESCE(). any help much appreciated. SELECT CASE WHEN A.[COL_1] LIKE '%cricket%' THEN 'ck' + ',' ELSE '' END +CASE WHEN A.[COL_1] LIKE '%soccer%' THEN 'sc' + ',' ELSE '' END +....CASE WHEN A.[RESIUTIL_DESC] LIKE '%base%ball' THEN 'BB' + ',' ELSE '' END FROM TableName A

Viewing all articles
Browse latest Browse all 3145

Trending Articles