Need help with a SQL statement defaulting to a specific value (ex if NULL, show 21)

Need help with a statement that will display the value in ctd.TAT_DAYS but when the value is null, default it to 21.

Ex. ctd.TAT_DAYS = 15, show 15 but if NULL show 21. The full statement is below. Thank you in advance for any help.
select wos.description STATUS
,woo.si_number WO_NUMBER
,pnm.pn PART_NUMBER
,pnm.description
,woo.WARRANTEE_FLAG
,woo.WO_UDF_010 AS WARRANTY_REQUESTED
,dpt.dept_name SHOP
,loc.location_code SHOP_LOCATION
,ctd.TAT_DAYS TARGET_TAT
,round(sysdate-woo.entry_date,0) DAYS_OPEN
,woo.last_status_chg
,round(sysdate-woo.LAST_STATUS_CHG,0) DAYS_IN_STATUS
,round((sysdate-woo.LAST_STATUS_CHG)*24,0) HOURS_IN_STATUS
,round(woo.due_date-sysdate,0) DAYS_LEFT
,hours_punched.hours,open_labor.name CURRENT_TECHNICIAN
,woo.woo_auto_key,woo.entry_date
,woo.due_date
,cmp.company_code CUSTOMER_CODE
,cmp.company_name CUSTOMER
,woo.priority
,ba_view_wo_summary.last_quote_approved
,decode(woo.ctd_auto_key,null,'N','Y') contract
,cth.contract_number
,cth.sdf_cth_001 contract_type
,woo.manual_ECD ECD
,sysur2.first_name||' '||sysur2.last_name TECHNICIAN
,sysur3.first_name||' '||sysur3.last_name INSPECTOR
from wo_operation woo
left join ba_view_wo_summary
on ba_view_wo_summary.wo_number=woo.si_number
inner join wo_status wos
on woo.wos_auto_key=wos.wos_auto_key
inner join parts_master pnm
on woo.pnm_auto_key=pnm.pnm_auto_key
inner join department dpt
on woo.dpt_auto_key=dpt.dpt_auto_key
left join companies cmp
on woo.cmp_auto_key=cmp.cmp_auto_key
left join  contract_detail ctd
on woo.ctd_auto_key=ctd.ctd_auto_key
left join contract_header cth
on ctd.cth_auto_key=cth.cth_auto_key
left join stock_reservations str
on woo.woo_auto_key=str.woo_auto_key
left join stock stm
on str.stm_auto_key=stm.stm_auto_key
left join location loc
on stm.loc_auto_key=loc.loc_auto_key
left join sys_users sysur2
on woo.SYSUR_MANAGER=sysur2.sysur_auto_key
left join sys_users sysur3
on woo.IQ_SYSUR_NOTIFY=sysur3.sysur_auto_key
left join
(select wo_operation.woo_auto_key,wo_operation.si_number WO_NUMBER,round((sysdate-start_time)*24,1) TIME_OPEN,sys_users.first_name||' '||sys_users.last_name NAME
from (
select wtl_auto_key,wot_auto_key,sysur_auto_key,wok_auto_key,start_time,hours
from wo_task_labor
where start_time is not null and stop_time is Null and delete_date is null
) labor
inner join wo_task
on labor.wot_auto_key=wo_task.wot_auto_key
inner join wo_operation
on wo_task.woo_auto_key=wo_operation.woo_auto_key
inner join wo_skills
on labor.wok_auto_key=wo_skills.wok_auto_key
inner join sys_users
on labor.sysur_auto_key=sys_users.sysur_auto_key
left join department
on wo_operation.dpt_auto_key=department.dpt_auto_key
order by TIME_OPEN desc) open_labor
on woo.woo_auto_key=open_labor.woo_auto_key
left join (select wo_task.woo_auto_key,sum(hours) hours  from
(select wot_auto_key,hours
from wo_task_labor
where delete_date is null) labor
inner join wo_task on labor.wot_auto_key=wo_task.wot_auto_key
group by wo_task.woo_auto_key) hours_punched
on woo.woo_auto_key=hours_punched.woo_auto_key
where woo.open_flag='T' and wos.description in ('OPEN','AWT SHOP EVAL','SHOP EVALUATION','AWT SHOP REPAIR','QUOTING','SCRAP','SHOP REPAIR','QC FINAL INSP','RETURN AS IS','QC IN-PROCESS')
order by woo.due_date asc

Open in new window

maximus1974Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
You can use a case statement to perform that.

CASE WHEN ctd.TAT_DAYS = NULL THEN 21 ELSE ctd.TAT_DAYS END

Open in new window

0
Martyn SpencerManaging DirectorCommented:
Use
nvl(ctd.TAT_DAYS, 21) as tat_days

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slightwv (䄆 Netminder) Commented:
>>CASE WHEN ctd.TAT_DAYS = NULL THEN 21 ELSE ctd.TAT_DAYS END

That won't work.  In Oracle nothing is '=' to a null.  

I would use the NVL above but the corrected CASE is:
CASE WHEN ctd.TAT_DAYS IS NULL THEN 21 ELSE ctd.TAT_DAYS END
0
Dustin SaundersDirector of OperationsCommented:
Woops, good catch thanks @slightwv
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.