MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 30th, 2004, 02:52 PM
mhepner mhepner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 mhepner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Need help with SELECT STATEMENT

I need help with a SELECT Statement.

I have a WCLASS TABLE WITH THREE ENTRIES. AN INBOUND TABLE WHERE I AM ONLY CONCERNED WITH THE DATE AND TICKET INFORMATION, AND IPDETAIL WHICH CONTAINS THE VALUES I WANT. WCLASS CONTAINS a WCLASS ID which allows me to join it to IPDETAIL. IPDETAIL contains TICKET which allows me to join it to INBOUND. There may or may not be values in INBOUND or IPDETAIL but I want the IDs displayed anyway and if another WCLASS was found for that date have the same date for the rest of the Weight Classes. I want to create a result set as follows: (WCLASS = A, IPDETAIL=B, INBOUND = C)

A.WCLASS C.DATE SUM(B.QUANTITY) SUM(B.AMOUNT)
1 9/12 12 120.00
2 9/12 NULL NULL
1 9/13 13 130.00
2 9/13 14 140.00
1 9/14 NULL NULL
2 9/14 15 150.00

Reply With Quote
  #2  
Old September 30th, 2004, 03:27 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
what have you tried already?

Reply With Quote
  #3  
Old September 30th, 2004, 03:35 PM
mhepner mhepner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 mhepner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is what I tried so far...

Select Wclass.id, Inbound.date, Count(ipdetail.wclass) As Count, Sum(ipdetail.quantity) As Quantity, Sum(ipdetail.amount) As Amount From Inbound Left Outer Join Ipdetail On Inbound.ticket = Ipdetail.ticket Right Outer Join Wclass On Ipdetail.wclass = Wclass.id Group By Wclass.id, Inbound.date

Reply With Quote
  #4  
Old October 1st, 2004, 06:31 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,954 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 38 m 56 sec
Reputation Power: 1024
uh oh

i never could wrap my head around a query that mixes left and right joins

just too logically complex for me, i guess

mhepner, your explanation of the tables is not enough for me to understand how they are related -- perhaps you could give a few sample rows from each table

also, the comment "if another WCLASS was found for that date have the same date for the rest of the Weight Classes" makes no sense to me at all

sorry
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Need help with SELECT STATEMENT


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT