Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Nested CASE expressions

$
0
0

Hi, For some reason when I use the below CASE expression in my SELECT statement I get duplicate records. Also tried using coalesce with no luck. How to write a nested CASE expression which would yeild just one expression. In case if I have to combine 2 different Expressions for 1 record, Is there a way to merge the 2 Expressions writing CASE expression something like below in SQL Server 2008 R2.

CASEWHEN<Condition 1>THEN<Expression 1>
WHEN<Condition 2>THEN<Expression 2>
WHEN<Condition 3>THEN<Expression 3>

WHEN<Condition 4>THEN<Expression 4>
ENDAS CaseResult

STUFF ((SELECT','+CASEWHEN<Condition 1>THEN<Expression 1>
WHEN<Condition 2>THEN<Expression 2>
WHEN<Condition 3>THEN<Expression 3>
WHEN<Condition 4>THEN<Expression 4>
END
FOR XML PATH(''), ROOT('MyString'), TYPE).value('/MyString[1]'<span clas


Ione


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>