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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Creating an SQL Query Help

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-03 : 08:13:29
Lynn Melough writes "Table 1: db_marketing.dbo.tbl_orders contains the following fields:
account_no
order_no
product_revenue
S_H_revenue
order_date
shipped_flag (Y/N)
keycode

I am new to creating a query, which gives the total number of gross orders, shipped orders, gross total revenue (product revenue + S&H revenue), and shipped total revenue for every Sunday between 1/1/04 and 2/23/04 in the state of New York for keycode AB01. Please output the query results into the table tbl_results in the database db_marketing.

I am on the right track, help!!!!


SELECT DISTINCTROW [Orders].account_no, Sum(CCur([Order].[product_revenue]+[S_H_revenue]) AS Subtotal
FROM db_marketing.dbo.tbl_orders
GROUP BY [Order].OrderID;
WHERE state = ‘NY’ AND keycode = ‘AB01’ AND tdate>=TO_DATE('1/4/04', ‘1/11/04’, ‘1/18/04’, ‘1/25/04, ‘2/1/04’, ‘2/8/04’, ‘2/15/04’, 'mm/dd/yy') AND tdate<=TO_DATE('2/22/04', 'mm/dd/yy')"

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-06-03 : 08:46:43
TO_DATE() - what is that? Looks like an Oracle Function. MS SQL Server has a function called DATEPART(dw, <date field>) dw = "day of week" returning an integer representing the day of the week.

Go to Top of Page
   

- Advertisement -