how do I select a column based on condition?
Select
ordr_num as num,
ordr_date as date,
CASE WHEN @status <> 'Cancelled' THEN ordr_ship_with ELSE NULL END as shipwith
From
order where ordr_num = @ordrNum
SELECT ordr_num as num, ordr_date as date,
CASE WHEN @status<>'Cancelled' THEN ordr_ship_with ELSE NULL END as shipwith
FROM order
WHERE ordr_num = @ordrNum
Try this out
Select
ordr_num as num,
ordr_date as date,
CASE
WHEN @Status <> 'Cancelled' THEN ordr_ship_with
ELSE NULL END
as shipwith
From order
where ordr_num = @ordrNum
Although I have a feeling that you STATUS is an actual column in the Order table. In that case, do this:
Select
ordr_num as num,
ordr_date as date,
CASE
WHEN Status <> 'Cancelled' THEN ordr_ship_with
ELSE NULL END
as shipwith
From order
where ordr_num = @ordrNum