Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Different Results; Same Query Request

Author  Topic 

confuzed04
Starting Member

39 Posts

Posted - 2007-05-29 : 15:38:43
Can you tell me why the following queries would give me slightly different results?

SELECT sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as Minutes
FROM VoiceCallDetailRecord
WHERE CallDate Between '02/19/2007' and '02/20/2007' and COS = 3
AND (((CONVERT(varchar, CallDate, 108) Between '21:00:00' AND '23:59:59') OR (CONVERT(varchar, CallDate, 108) Between '00:00:00' AND '07:00:00'))
OR DATEPART(weekday, CallDate) in (1,7))
UNION
SELECT sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as Minutes
FROM ZeroChargeVCDRecord
WHERE CallDate Between '02/19/2007' and '02/20/2007' and COS = 3
AND (((CONVERT(varchar, CallDate, 108) Between '21:00:00' AND '23:59:59') OR (CONVERT(varchar, CallDate, 108) Between '00:00:00' AND '07:00:00'))
OR DATEPART(weekday, CallDate) in (1,7))


SELECT dateadd(day, datediff(day, 0, CallDate), 0) as CallDate,sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as Minutes
FROM VoiceCallDetailRecord
WHERE CallDate Between '02/19/2007' and '02/20/2007' and COS = 3
AND (((CONVERT(varchar, CallDate, 108) Between '21:00:00' AND '23:59:59') OR (CONVERT(varchar, CallDate, 108) Between '00:00:00' AND '07:00:00'))
OR DATEPART(weekday, CallDate) in (1,7))
GROUP BY dateadd(day, datediff(day, 0, CallDate), 0)
UNION
SELECT dateadd(day, datediff(day, 0, CallDate), 0) as CallDate,sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as Minutes
FROM ZeroChargeVCDRecord
WHERE CallDate Between '02/19/2007' and '02/20/2007' and COS = 3
AND (((CONVERT(varchar, CallDate, 108) Between '21:00:00' AND '23:59:59') OR (CONVERT(varchar, CallDate, 108) Between '00:00:00' AND '07:00:00'))
OR DATEPART(weekday, CallDate) in (1,7))
GROUP BY dateadd(day, datediff(day, 0, CallDate), 0)

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-29 : 15:57:27
One is grouping on an expression, the other isn't.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

confuzed04
Starting Member

39 Posts

Posted - 2007-05-29 : 16:06:38
So, which one is the most accurate one??
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-05-29 : 16:14:17
quote:
Originally posted by confuzed04

So, which one is the most accurate one??



Accurate as to what?

That's your call, unless you tell us what the results are suppose to be.

Read the hint link in my sig and post what it asks for



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -