Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-04, 15:26
jhobbs jhobbs is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
Query help

I'm working on project that deals with upc numbers along with a quantity sold and retail numbers and such. My problem is that I have the same upc number on multiple times, I need these upc numbers to only appear once and have the other corresponding data to add up and appear on that same line.

Here is the code I am using:

PARAMETERS [Beginning Date] DateTime, [Ending Date] DateTime;
SELECT HIDATA60404.UPC, HIDATA60404.LONG_NAME, HIDATA60404.INV_SDESC, HIDATA60404.DEPARTMENT, HIDATA60404.CATEGORY, HIDATA60404.QSOLD, HIDATA60404.DSOLD, HIDATA60404.TOTALCOST, HIDATA60404.PROFIT, HIDATA60404.GPROFIT
FROM HIDATA60404
WHERE (((HIDATA60404.ELSDATE) Between [Beginning Date] And [Ending Date]) AND (([HIDATA60404]![ELSSTORE]) Like [store]) AND (([HIDATA60404]![CATEGORY])=[cat])) OR ((([store]) Is Null));

Thanks for any help you can provide.
Reply With Quote
  #2 (permalink)  
Old 06-09-04, 15:40
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,572
Are you looking for Sum() and GROUP BY ?

-PatP
Reply With Quote
  #3 (permalink)  
Old 06-09-04, 15:52
jhobbs jhobbs is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
Honestly, I'm not sure where to go from here, It's been about 4-5 years since I've done any of this and I'm just trying to remember what I've done in the past. I thought it was somewhere along the lines of Select Distinct, but I have no clue if that's right.
Reply With Quote
  #4 (permalink)  
Old 06-09-04, 16:08
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,572
Can you post a sample that shows around a dozen rows of data, and the corresponding result set that you'd like to see?

-PatP
Reply With Quote
  #5 (permalink)  
Old 06-09-04, 16:33
jhobbs jhobbs is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
Using the following code, I get 40 rows returned. Combining the results should make 17.

SELECT HIDATA60404.UPC, HIDATA60404.LONG_NAME, HIDATA60404.INV_SDESC, HIDATA60404.DEPARTMENT, HIDATA60404.CATEGORY, HIDATA60404.QSOLD, HIDATA60404.DSOLD, HIDATA60404.TOTALCOST, HIDATA60404.PROFIT, HIDATA60404.GPROFIT
FROM HIDATA60404
WHERE ((([HIDATA60404]![ELSSTORE])="10" And ([HIDATA60404]![ELSSTORE])="10") AND (([HIDATA60404]![CATEGORY])="141" And ([HIDATA60404]![CATEGORY])="141") AND ([HIDATA60404]![ELSDATE]>#5/23/2004# And [HIDATA60404]![ELSDATE]<#5/27/2004#));

I need the corresponding columns to total up with the single row i post.
Attached Files
File Type: txt test.txt (8.4 KB, 44 views)
Reply With Quote
  #6 (permalink)  
Old 06-09-04, 16:45
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,572
I can't find the results that you wanted to see, so this is just a guess, but I'm reasonably sure that you want to group by the first column, and Sum() the numeric columns.

-PatP
Reply With Quote
  #7 (permalink)  
Old 06-09-04, 17:14
jhobbs jhobbs is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
Question

I tried that. It groups the items together, but still shows up on multiple lines.

This is frustrating.
Reply With Quote
  #8 (permalink)  
Old 06-09-04, 17:26
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,572
If all you want is the "galactic total", just leave off the GROUP BY.

-PatP
Reply With Quote
  #9 (permalink)  
Old 06-10-04, 09:01
jhobbs jhobbs is offline
Registered User
 
Join Date: Jun 2004
Posts: 20
I did end up getting this to work. I had been trying that all day, Thanks for all your help.

Jeff
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On