SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL 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 ASP Free Forums Sponsor:
  #1  
Old May 21st, 2004, 11:30 AM
toddcallen toddcallen is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 toddcallen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Need Help Merging 2 SQL queries

I have a situation where I need an SQL statement that is beyond my current skills.
I created a query in Access, then created a second query based upon the first one. I get good data out of Access, but I need to merge both statements into a single query that I can use in ASP page.

Here is the code to both queries:

Code:
  
QUERY 1 (kevin)

SELECT tbl_Parts.int_Part_Report_ID

FROM tbl_Assigned_Assemblies INNER JOIN tbl_Parts ON tbl_Assigned_Assemblies.int_Asm_ID=tbl_Parts.int_A  sm_ID

WHERE (((tbl_Assigned_Assemblies.txt_Vehicle)="2004 Malibu") AND ((tbl_Parts.dat_Part_Entry_Date) Between #5/1/2004# And #5/31/2004#))

 

 

 

QUERY 2 (based on kevin)

SELECT tbl_Assigned_Assemblies.txt_Vehicle, tbl_Assigned_Assemblies.txt_Assembly_Type, tbl_Parts.txt_Defect, Count(tbl_Parts.int_Part_Report_ID) AS Total, Sum(IIf([txt_Part_Status]='Under Investigation',1,0)) AS [Open], Sum(IIf([txt_Part_Status]<>'Under Investigation',1,0)) AS Closed

FROM tbl_Assigned_Assemblies INNER JOIN tbl_Parts ON tbl_Assigned_Assemblies.int_Asm_ID=tbl_Parts.int_A  sm_ID

WHERE

(SELECT tbl_Parts.int_Part_Report_ID

FROM tbl_Assigned_Assemblies INNER JOIN tbl_Parts ON tbl_Assigned_Assemblies.int_Asm_ID=tbl_Parts.int_A  sm_ID

WHERE (((tbl_Assigned_Assemblies.txt_Vehicle)="2004 Malibu") AND ((tbl_Parts.dat_Part_Entry_Date) Between #5/1/2004# And #5/31/2004#)))

GROUP BY tbl_Assigned_Assemblies.txt_Vehicle, tbl_Assigned_Assemblies.txt_Assembly_Type, tbl_Parts.txt_Defect




Some help would be GREATLY appreciated.

Reply With Quote
  #2  
Old May 21st, 2004, 11:35 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
What is tbl_Parts.int_Part_Report_ID
suppose to equal in you 2nd query

S-

Reply With Quote
  #3  
Old May 21st, 2004, 11:40 AM
toddcallen toddcallen is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 toddcallen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by sbaxter
What is tbl_Parts.int_Part_Report_ID
suppose to equal in you 2nd query

S-

The tbl_Parts.int_Part_Report_ID field is the unique recod identifier for the parts I will eventually be counting. The first query narrows the returned records to those with the correct vehicle and to those entered in the specified timeframe. The second query counts the remaining parts based on their part status, separating them into either OPEN (under investigation) or CLOSED (any other status).

Does this help?

Reply With Quote
  #4  
Old May 21st, 2004, 04:41 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
So the two queries query seperate information and you want brought back together. Correct??

If so look into using UNION in you query to bring the two queries together

S-

Reply With Quote
  #5  
Old May 21st, 2004, 05:33 PM
toddcallen toddcallen is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 11 toddcallen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Quote:
Originally Posted by sbaxter
So the two queries query seperate information and you want brought back together. Correct??

If so look into using UNION in you query to bring the two queries together

S-

Actually, just the opposite. The first is the filter and the second is the counter.

Several people at work have worked with me on this and the answer turned out to involve nesting the first query into the second query's WHERE statement.

Thanks for the attention though. I was really stumped and grasping at straws.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Need Help Merging 2 SQL queries


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 6 hosted by Hostway
Stay green...Green IT