Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

isnull not working 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
0
0
US
Hello,
I have written a sproc that I added an isnull statement into it. I am not getting an error but when I look at the results I still get NULL in the column. This is my first time writing a sproc from scratch. Any help would be greatly appreciated.

Tom

Code:
DECLARE @clnt int,@uci varchar(15),@pd int

SET @clnt = 69
SET @uci = 'VIT'
SET @pd = 377

SELECT 
@uci as UCI
,@pd as pd
,(case when ar.transagebucket < 1 then '0_30'
		when ar.transagebucket = 1 then '31_60'
		when ar.transagebucket = 2 then '61_90'
		when ar.transagebucket = 3 then '91_120'
		when ar.transagebucket = 4 then '121_150'
		when ar.transagebucket = 5 then '151_180'
		else 'Over180' end) as AgeBucket
,ar.PatName as PatientName
,ar.AcctNu as AccountNumber
,ar.dos as Svc_Date
,ar.cptdisplay
,(ins.insdesc+ ' - ' +ins.insmne) as Insurance
,ar.chgamt
,(case when adj.trantype = 3 and adj.adjcat = 'WRITE_OFF' then isnull(adj.adjamt,0) END) as wo
,pmt.pmtamt
,ar.curbal
FROM rpt_dat_ARDetail ar
	INNER JOIN rpt_FYinfo fy ON ar.reportmonth = fy.monasdt 
	AND  ar.uci = fy.uci 
	INNER JOIN rpt_dic_Ins ins ON ar.insmne = ins.insmne AND ar.clntid = ins.clntid
	INNER JOIN rpt_dat_PmtDetail pmt ON ar.clntid = pmt.clntid
	AND ar.AcctNu = pmt.AcctNu AND ar.dos = pmt.dos
	INNER JOIN rpt_dat_AdjustmentDetail adj ON ar.clntid = adj.clntid AND ar.aid = adj.aid
WHERE ar.clntid = @clnt AND fy.rptpd = @pd AND fy.rptpd = adj.rptpd 
ORDER BY ar.transagebucket,ar.PatName,ar.chgamt,ar.curbal;
 
Your IsNull only kicks in when adj.trantype = 3 and adj.adjcat = 'WRITE_OFF'. I suspect the NULL values you are seeing are for rows that do not meet that criteria. You could wrap the whole CASE statement in IsNull.

Code:
,IsNull(CASE when adj.trantype = 3 and adj.adjcat = 'WRITE_OFF' then adj.adjamt END,0) as wo


--JD
"Behold! As a wild ass in the desert go forth I to my work."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top