How we can use comparisons in THEN
section of a CASE/WHEN/THEN
structure in SQL Server?
For example:
<code>SELECT
A, B, C
(CASE
WHEN A > B
THEN C = 2
ELSE 0
END) AS D
FROM T
</code>
<code>SELECT
A, B, C
(CASE
WHEN A > B
THEN C = 2
ELSE 0
END) AS D
FROM T
</code>
SELECT
A, B, C
(CASE
WHEN A > B
THEN C = 2
ELSE 0
END) AS D
FROM T
Here I want to have result of B = 2 in THEN
section, I know that we can move the “C=2” to the WHEN section but I need it in the THEN section.
3