excelguy
excelguy

Reputation: 1624

SQL Case Statement, Alias values with 2 conditions

Trying to do a case statement with 2 values. I tried following SQL Case with 2 conditions example but unable to get it.

Logic trying to do: where stack is in nodeName and overflow is in scenarioName, then replace nodeName value Stack with Usethisvalue, within the nodeName column.

My query:

SELECT endOfDay as businessDate,
(CASE nodeName,
WHEN nodeName = 'Stack' AND scenarioName = 'Overflow' THEN Usethisvalue
END) as nodeName,
scenarioName, Value
FROM CONTRIBUTION 

Can anyone help with this?

Upvotes: 0

Views: 49

Answers (2)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31991

try like below

SELECT endOfDay as businessDate,
CASE WHEN nodeName = 'Stack' AND scenarioName = 'Overflow' THEN 'Usethisvalue'
else nodeName END as nodeName,
scenarioName, Value
FROM CONTRIBUTION

Upvotes: 3

AlexARH
AlexARH

Reputation: 212

SELECT
endOfDay as businessDate, nodeName, WHEN nodeName = 'Stack' AND scenarioName = 'Overflow' THEN Usethisvalue ELSE nodeName END as nodeName, scenarioName, Value FROM CONTRIBUTION

Upvotes: 0

Related Questions