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
 Creating query with long range date interval

Author  Topic 

ewan
Starting Member

13 Posts

Posted - 2011-12-08 : 04:43:03
I'm doing a query where I must display the records with date interval of 1 year or more than, then it also has a specific time range of 12:00AM to 06:00AM. How can I do this? I'm using a MSSQL Syntax.this is my code, is there anything wrong with it or it just me?

SELECT A1.RestaurantCode, A1.RestaurantName, COUNT(A1.RestaurantCode) AS TC, SUM(A2.GrossTotal) AS Sales
FROM RestaurantMaster A1, OrdersHistory A2
WHERE A1.PKID = A2.RestaurantID AND A2.OrderDate BETWEEN '2010-02-13 00:00:00' AND '2011-02-13 06:00:00'
GROUP BY A1.RestaurantCode, A1.RestaurantName
ORDER BY A1.Restaurant Code;

I really need a help or I will be damn.

jeneca

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-08 : 07:20:56
[code]
SELECT A1.RestaurantCode, A1.RestaurantName, COUNT(A1.RestaurantCode) AS TC, SUM(A2.GrossTotal) AS Sales
FROM RestaurantMaster A1
INNER JOIN OrdersHistory A2 ON A1.PKID = A2.RestaurantID
WHERE A2.OrderDate >= '2010-02-13'
AND A2.OrderDate < '2011-02-14'
AND CONVERT(VARCHAR(5), A2.OrderDate, 108) BETWEEN '00:00' AND '06:00'
GROUP BY A1.RestaurantCode, A1.RestaurantName
ORDER BY A1.Restaurant Code;
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -