473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help with SQL Statement

OK..not a total noob, but I really need help with a fairly complex (for me anyway) thing I'm trying to accomplish:

I need to create a "report" based on data in a MS SQL 2000 dataset that can be run. What I'm trying to get is a summary report of all transactions in a given date range broken down by "Department" (there are seven in my case). The data should be the Qty of transactions for each department and the $ total of all transaction in the department over the time period. I'll be doing a little math with these after the fact to get Average $ of each transaction for each department and what % of each contributes to the total of 100%, so any extra "bonus" advice for these if they make sense to incorporate would be great too!.

Not sure exactly what someone needs to be able to help here, so I'll throw out everything I can think of and let the suggestions/questions come.

There are (I think) several tables involved to get/do this. First, the "Departments" table (to get Department Names and the field within that stores the names is "Name".

Next, we need to look in the "[Transaction]" (t) table to find all transactions in a timeframe (this is where dates/times are stored) and in order to really drill into the details of the transaction, we'll add "TransactionEntry" (te) as an additional table. These two join on t.TransactionNumber = te.TransactionNumber

Now in order to Join Department to TransactionEntry, we have to use the common table "Item" (i) where i.id = te.itemid, and finally join "Department" (d) to "Item" (i) where i.Departmentid = d.id

The resulting SQL statement (if someone can help me make it happen) will be called from ColdFusion MX 7 pages on a Windows 2003 server platform, not that that probably makes a difference...

(What I currently have that's not doing it is this:)
Expand|Select|Wrap|Line Numbers
  1. SELECT d.Name AS dName, SUM(te.Quantity) AS nQuantity, te.Price AS nPrice
  2. FROM TransactionEntry te
  3. INNER JOIN [Transaction] t ON te.TransactionNumber = t.TransactionNumber
  4. LEFT JOIN Item i ON te.ItemID = i.id
  5. LEFT JOIN Department d ON i.DepartmentID = d.id
  6. WHERE te.StoreID IN ( 101 )
  7. AND t.Time <=     <cfqueryparam cfsqltype="cf_sql_timestamp"     value="#CreateODBCDate(FORM.dTo)#" />
  8. AND t.Time >=     <cfqueryparam cfsqltype="cf_sql_timestamp"     value="#CreateODBCDate(FORM.dFrom)#" />
  9. GROUP BY d.Name, i.id, te.Price
  10. ORDER BY d.Name ASC            
  11.  
Ideas? Thanks in advance to anyone that helps/attempts!
Jul 25 '07 #1
0 971

Sign in to post your reply or Sign up for a free account.

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
6
by: redashley40 | last post by:
This is my first attempt in SQL and PreparedStatement I have add the PreparedStatement and I'm not to sure if I'm doing it correctly. When I do a test run on Choose 1 ,or 2 I get this error. Error...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
2
by: nleake | last post by:
Hey, I've been trying to use Python to help me with some DNA sequencing work. I've figured out how to use Biopython for the importing work; however, I need some python code to help me remove a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.