Solved

Why am I getting different results with theses queries?

Posted on 2012-03-20
3
202 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
ID: 37743957
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
ID: 37744047
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
ID: 37744357
null is ignored in count...
0 is counted as a separate item...
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server tables join on parse list 6 22
migrate a SQL 2008 to 2016, 2 29
SQL Improvement  ( Speed) 14 27
How to debug a store procedure in MS SQL 2008? 3 10
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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