Reputation: 854
I have created a calculated column but it is giving me a row with null value. If I add another calculated field, it adds 2 null rows, and so on.
My objective is to get a single row with a single value. No nulls.
The code:
SELECT
CLIENT_CODE,
( CASE WHEN CLITBP.TBPCODIGO=101 THEN COALESCE( CLITBP.TBPDESC2,0) ELSE NULL END) TAB101
FROM
CLIENT
GROUP BY 1,2
the wrong output
the intended output
Upvotes: 1
Views: 59
Reputation: 1270573
If you want one row per client code, then you should have only one key in the GROUP BY
. Perhaps this is what you want:
SELECT CLIENT_CODE,
MAX(CASE WHEN CLITBP.TBPCODIGO = 101 THEN COALESCE(CLITBP.TBPDESC2, 0) END) as TAB101
FROM CLIENT
GROUP BY CLIENT_CODE;
Upvotes: 1