?
Solved

Why am I getting different results with theses queries?

Posted on 2012-03-20
3
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
HainKurt earned 2000 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 58

Expert Comment

by:HainKurt
ID: 37744357
null is ignored in count...
0 is counted as a separate item...
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

764 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