Question : sql question

I have the following sql:

SELECT Distinct a.ASS_ID, projmatl.rowpointer, projmatl.proj_num, projmatl.item, projmatl.item_desc, projmatl.u_m, projmatl.matl_qty, projmatl.seq, projmatl.task_num, a.ShipRemaining, a.QtyRequired, job.job, a.rowpointer, a.notes, a.LoadSum
 FROM projmatl LEFT OUTER JOIN  
 job ON projmatl.proj_num = job.ord_num AND projmatl.item = job.item AND projmatl.task_num = job.ord_line AND projmatl.seq = job.ord_release LEFT OUTER JOIN
AGRAMaster.dbo.ACS_ControlMaster AS a ON a.rowpointer = projmatl.rowpointer
WHERE
(projmatl.proj_num = @PARM0 Order by projmatl.seq, projmatl.item_desc


What I would like to do is populate a.QtyRequired from projmatl.matl_qty if the join for a. QtyRequired returns null or ‘0’

Answer : sql question

No, I had a typo :)


SELECT Distinct a.ASS_ID, projmatl.rowpointer, projmatl.proj_num, projmatl.item, projmatl.item_desc,
projmatl.u_m, projmatl.matl_qty, projmatl.seq, projmatl.task_num, a.ShipRemaining,
CASE WHEN COALESCE(a.QtyRequired, 0) > 0 THEN a.QtyRequired ELSE projmatl.matl_qty END AS QtyRequired,
job.job, a.rowpointer, a.notes, a.LoadSum
 FROM projmatl LEFT OUTER JOIN  
 job ON projmatl.proj_num = job.ord_num AND projmatl.item = job.item AND projmatl.task_num = job.ord_line AND projmatl.seq = job.ord_release LEFT OUTER JOIN
AGRAMaster.dbo.ACS_ControlMaster AS a ON a.rowpointer = projmatl.rowpointer
WHERE
(projmatl.proj_num = @PARM0 Order by projmatl.seq, projmatl.item_desc


Left out the WHEN
Random Solutions  
 
programming4us programming4us