| Author |
Topic |
|
confuzed04
Starting Member
39 Posts |
Posted - 2007-06-13 : 11:39:33
|
| I have the following query and I am wanting to get the results to be in order. Right now, it shows me the results by date, but the dates are out of order. How can I get it to give me the results by date in date order???SELECT DISTINCT MDN, dateadd(day, datediff(day, 0, CallDate), 0) as CallDate,sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as MinutesFROM VoiceCallDetailRecord WHERE CallDate >= '02/19/2007' and calldate < '03/19/2007' and NOT (Left(Endpoint,3) IN ('011') or (Left(Endpoint,4) IN ('1340','1876','1868','1809', '1246','1242','1780','1403', '1250','1604','1807','1519', '1204','1506','1709','1867', '1902','1705','1613','1416', '1905','1902','1514','1450', '1418','1819','1306','1867')))AND (((CONVERT(varchar, CallDate, 108) Between '07:00:00' AND '20:59:59'))AND DATEPART(weekday, CallDate) in (2,3,4,5,6)) Group By MDN, dateadd(day, datediff(day, 0, CallDate), 0)UNION SELECT DISTINCT MDN, dateadd(day, datediff(day, 0, CallDate), 0) as CallDate,sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as MinutesFROM ZeroChargeVCDRecord WHERE CallDate >= '02/19/2007' and calldate < '03/19/2007' and NOT (Left(Endpoint,3) IN ('011') or (Left(Endpoint,4) IN ('1340','1876','1868','1809', '1246','1242','1780','1403', '1250','1604','1807','1519', '1204','1506','1709','1867', '1902','1705','1613','1416', '1905','1902','1514','1450', '1418','1819','1306','1867')))AND (((CONVERT(varchar, CallDate, 108) Between '07:00:00' AND '20:59:59'))AND DATEPART(weekday, CallDate) in (2,3,4,5,6))Group By MDN, dateadd(day, datediff(day, 0, CallDate), 0) |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-13 : 11:42:18
|
add to the end of the queryORDER BY CallDate KH |
 |
|
|
confuzed04
Starting Member
39 Posts |
Posted - 2007-06-13 : 12:00:24
|
| I did this and it won't let me run it with a UNION statement. I have to eliminate the UNION and leave a black line to get it to run and then my results aren't combined. Please advise |
 |
|
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2007-06-13 : 12:03:21
|
| You have to put the ORDER BY CallDate only after the second SELECT statement.SQL Server Helperhttp://www.sql-server-helper.com |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-13 : 12:03:36
|
only add the ORDER BY to the end<your existing query>ORDER BY CallDate KH |
 |
|
|
confuzed04
Starting Member
39 Posts |
Posted - 2007-06-13 : 14:37:29
|
| Oh! Thanks so much!! |
 |
|
|
|
|
|