Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Need help with this CASE statement

$
0
0

Hi everyone,

I would like to create a CASE that references another view and uses fields in that view to create a new field in a new view.

The fields I am working with are called LEVEL_CD and AVAILABLE_AMT.

In this case I would like to create a field called AVAILABLE_AMT (in my new view) that inserts the AVAILABLE_AMT from the old view into the new field only if the LEVEL_CD = 1. If the LEVEL_CD is anything else but 1 I would like to insert a 0 into my new AVAILABLE AMOUNT field.

This is what I have so far and it doesn't seem to work:

CASE WHEN old_view.LEVEL_CD = 1 THEN old_view.AVAILABLE_AMT
WHEN old_view.LEVEL_CD <> 1 THEN 0 END AS AVAILABLE_AMT

This just gives me zeroes in every record. Can anybody spot what I am doing wrong?

Thanks!




Viewing all articles
Browse latest Browse all 8428

Trending Articles



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