472,984 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Joinging multiple select query into one select query(multiple tables and attributes)

1
Hi!
II was wondering if you can help me with SQL query..

Below 7 separated select query works fine(only when they are retrieved separately)
But I want to combined them together and so that i can make report from my database on the one sheet rather than querying each select statement ( I will use MS Query from the Excel)
================================================== =======
1)

select convert(varchar, create_date_time, 112) as Date, count(pkt_ctrl_nbr) as Count
from outpt_pkt_hdr (nolock) where stat_code<>99
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)

2)
select convert(varchar, create_date_time, 112) as Date, sum(units_pakd) as "Sum Units"
from outpt_carton_dtl (nolock)
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)

3)

select convert(varchar, create_date_time, 112) as Date, sum(units_pakd) as "Units Sum"
from outpt_carton_dtl (nolock) where style like 'S%'
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)



4)
select convert(varchar, create_date_time, 112) as Date, sum(units_pakd) as "Units Sum"
from outpt_carton_dtl (nolock) where style not like 'S%'
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)

5)
select convert(varchar, create_date_time, 112) as Date, count(carton_nbr) as Count
from outpt_carton_hdr (nolock)
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)

6)

select convert(varchar, create_date_time, 112) as Date, count(carton_nbr) as Count
from outpt_carton_hdr (nolock) where carton_size in ('A4', 'A5')
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)

7)
select convert(varchar, create_date_time, 112) as Date, count(carton_nbr) as Count
from outpt_carton_hdr (nolock) where carton_type = 'POS'
group by convert(varchar, create_date_time, 112)
order by convert(varchar, create_date_time, 112)

================================================== =======

Below is what I combined

It works fine!

But!! If you see above language, there are WHERE attribute in each SELECT Query
which is in order to get desired data only.
(If I use below query, it comes with Mass!!)
So we need to put WHERE attribute somewhere below
(I need to have where attribute in each different columns as seen above statement)
However, since I already input some query in order to join them in WHERE attribute, I am confused how I can do.



++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++

SELECT OUTPT_PKT_HDR.CREATE_DATE_TIME AS 'Date',
Count(OUTPT_PKT_HDR.PKT_CTRL_NBR) AS 'SO',
Sum(OUTPT_CARTON_DTL.UNITS_PAKD) AS 'SU',
Sum(OUTPT_CARTON_DTL.UNITS_PAKD) AS 'SUP',
Sum(OUTPT_CARTON_DTL.UNITS_PAKD) AS 'SUS',
Count(OUTPT_CARTON_HDR.CARTON_NBR) AS 'SC',
Count(OUTPT_CARTON_HDR.CARTON_NBR) AS 'SCJ',
Count(OUTPT_CARTON_HDR.CARTON_NBR) AS 'SCP'

FROM PKMS.dbo.OUTPT_CARTON_DTL OUTPT_CARTON_DTL,
PKMS.dbo.OUTPT_CARTON_HDR OUTPT_CARTON_HDR,
PKMS.dbo.OUTPT_PKT_HDR OUTPT_PKT_HDR

WHERE OUTPT_PKT_HDR.INVC_BATCH_NBR = OUTPT_CARTON_DTL.INVC_BATCH_NBR AND

OUTPT_PKT_HDR.PKT_CTRL_NBR = OUTPT_CARTON_DTL.PKT_CTRL_NBR AND
OUTPT_CARTON_HDR.CARTON_NBR = OUTPT_CARTON_DTL.CARTON_NBR AND
OUTPT_CARTON_HDR.INVC_BATCH_NBR = OUTPT_CARTON_DTL.INVC_BATCH_NBR AND
OUTPT_CARTON_HDR.INVC_BATCH_NBR = OUTPT_PKT_HDR.INVC_BATCH_NBR AND
OUTPT_CARTON_HDR.PKT_CTRL_NBR = OUTPT_PKT_HDR.PKT_CTRL_NBR

GROUP BY OUTPT_PKT_HDR.CREATE_DATE_TIME
ORDER BY OUTPT_PKT_HDR.CREATE_DATE_TIM

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++


Anyway, Thank you in advance


^____________^
Feb 12 '07 #1
0 7452

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

Similar topics

1
by: Chris | last post by:
Hi, I just would like to iterate through some attributes of a tag (Section). Sometimes I only need one attribute and sometimes I need all attributes. In a xsl:param I declare the attribute name...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
1
by: Felix_WafyTech | last post by:
Hi, I'm working with the ObjectDatasource and the application is getting more and more chatty. Is there a way I could make the ObjectDatasource support multiple DataTables that could be...
2
by: limpsharp | last post by:
Hi, I'm at the end of a work project and the final report has got me stumped. I have a table of employees, a table of modules and a link table of modules and employees and whether or not the...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
5
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
2
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've...
8
by: sloney | last post by:
I am trying to build relationships between mulitple tables and was wondering if there is a way to determine all tables in a database that contain the same attribute. Thanks in advance for your...
2
by: oneraven | last post by:
I want to have people search for people by professional function, and limit that search to the areas in which the professional is willing to travel to/work in. The areas are broken down into...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.