Solved

Why am I getting different results with theses queries?

Posted on 2012-03-20
3
196 Views
Last Modified: 2012-03-20
I am trying to clean up a query that I use everyday, but cannot understand why these queries would result in different data. Both queries are reporting daily unique new approved applications.Anyone see what I may be missing?
declare @fiscalyear as int
declare @fiscalmonth as int
set @fiscalyear = '2012'
set @fiscalmonth = '201203'

Select DATE,
count(distinct case when loan_type = 'pdl' and app_type = 'std' and cust_type = 'new' and processing_status <> 'denied'
	and (reason_for_denial not in('auto withdrawl during esign !','Auto Withdrawn During LatitudePayment Return !','Alternate Product ILP Accepted'
	,'Fraud','DNQ - Direct Deposit','DNQ - No Longer Employed','DNQ - Income','DNQ - Card Account','DNQ - Work Number',
	'DNQ - Home/Cell Number','Store Collections','Auto Withdrawn During ACH Return !') or (reason_for_denial is NULL)) 
	then bo_code else 0 end) as 'PDL New Approved'
from USOnlineReporting.dbo.BO_IN_APP_QUEUE bia
inner join USOnlineReporting.dbo.Business_Dates_All bda on bda.Date = dateadd(dd,0,datediff(dd,0,app_date))
where FiscalYear = @fiscalyear
and FiscalMonth = @fiscalmonth
group by date
order by date

Open in new window

SELECT dateadd(dd,0,datediff(dd,0,APP_DATE)),
COUNT(distinct((bo_in_app_queue.BO_CODE))) as New_Approved
FROM USOnlineReporting.dbo.BO_IN_APP_QUEUE
WHERE (APP_TYPE='STD') 
AND (LOAN_TYPE='PDL')
AND (PROCESSING_STATUS<>'DENIED')
AND (CUST_TYPE='NEW')
AND (REASON_FOR_DENIAL not in('auto withdrawl during esign !','Auto Withdrawn During LatitudePayment Return !','Alternate Product ILP Accepted'
,'Fraud','DNQ - Direct Deposit','DNQ - No Longer Employed','DNQ - Income','DNQ - Card Account','DNQ - Work Number',
'DNQ - Home/Cell Number','Store Collections','Auto Withdrawn During ACH Return !') OR (REASON_FOR_DENIAL is NULL))
and dateadd(dd,0,datediff(dd,0,APP_DATE)) >= '2/26/2012'
group by dateadd(dd,0,datediff(dd,0,APP_DATE))
order by dateadd(dd,0,datediff(dd,0,APP_DATE))

Open in new window

0
Comment
Question by:dplowman
  • 2
3 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
what data you get from both queries?

if you change this line

then bo_code else 0 end) as 'PDL New Approved'
>>>
then bo_code else null end) as 'PDL New Approved'

do you get same result?
0
 

Author Comment

by:dplowman
Comment Utility
Thanks, that was it. It actually solved the majority of my problem. Why would the 0 throw the data off compared to using null?
0
 
LVL 51

Expert Comment

by:HainKurt
Comment Utility
null is ignored in count...
0 is counted as a separate item...
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now