mardi 28 juillet 2015

Where would I add an IF statement to this SQL query?

I need to add an IF statement that says: If item.decifld1=0 or NULL, consider it as 999999, otherwise simply use the value of item.decifld1 found.

CODE

SELECT
   job.whse
  ,SUM(CEILING((job.qty_released/item.decifld1))) AS Sum_pallet_qty_released
  ,SUM(CEILING((job.qty_complete/item.decifld1))) AS Sum_pallet_qty_complete
  ,SUM(CEILING(((job.qty_released-job.qty_complete)/item.decifld1))) AS Sum_pallet_qty_remaining
  ,SUM(job.qty_released) AS Sum_qty_released
  ,SUM(job.qty_complete) AS Sum_qty_complete
  ,SUM(job.qty_released-job.qty_complete) AS Sum_qty_remaining
FROM
  job
INNER JOIN
  item
ON
  job.item=item.item
WHERE
  job.job_date = @job_date
  AND job.job NOT LIKE 'HK%'
  AND job.job NOT LIKE 'HR%'
  AND job.job NOT LIKE 'MMR%'
  AND job.job NOT LIKE 'SS%'
  AND job.job NOT LIKE 'SU%'
  AND job.job NOT LIKE 'TR%'
  AND job.job NOT LIKE 'WC%'
  AND job.job NOT LIKE 'MN%'
  AND job.job NOT LIKE 'QC%'
  AND job.job NOT LIKE 'SC%'
  AND job.job NOT LIKE 'CLN%'
  AND job.job NOT LIKE 'NR%'  
  AND job.job NOT LIKE 'WHS%'
  AND job.job NOT LIKE 'Bill%'
  AND job.job NOT LIKE 'PR%'
  AND job.job NOT LIKE 'WR%'
GROUP BY
  job.whse

Aucun commentaire:

Enregistrer un commentaire