Joining these two queries
I have two queries. The First one is long but very simple. All it has is long list of columns.
First one:
SELECT CL.CLIENT_ID, CA.CASE_ID, to_char(SYSDATE,'RRMMDD'),
CL.MASTER_CLIENT_ID,
CL.NAME1,
nvl(CL.NAME2,' '),
nvl(CL.ADDRESS1,' '),
nvl(CL.ADDRESS2,' '),
CL.POCO_POSTAL_CODE, nvl(CL.CITY,' '),
nvl(CL.AUTO_SURV_CODE,0),
CA.Col_Collector_Id
FROM CLIENT CL, CASES CA
WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID AND
CA.CASE_ID = :current_case_id
Second one:
SQL SELECT nvl(REF_NO,' '), nvl(to_char(DATE_OF_JUDGEMENT,'rrmmdd'),' ')
FROM CASE_INSTANCES
WHERE IN_INSTANCE_TYPE IN (1,8) AND
CA_CASE_ID = :current_case_id AND
PETITION_DATE = (SELECT max(PETITION_DATE)
FROM CASE_INSTANCES
WHERE IN_INSTANCE_TYPE IN (1,8)
AND CA_CASE_ID = :current_case_id
AND ROWNUM < 2 );
The :current_case_id is passed as a parameter. The table in the second query i.e. CASE_INSTANCES is related to the first query with the CA_CASE_ID. Not all records fetched by the first query have a record in the second query. So you might have to use a LEFT JOIN or something. trying to join these two has worn me out. Please help me out someone.
Hi,
Simplified Solution:
SELECT * FROM (
SELECT CL.CLIENT_ID, CA.CASE_ID, TO_CHAR(SYSDATE,'RRMMDD'),
CL.MASTER_CLIENT_ID,
CL.NAME1,
NVL(CL.NAME2,' '),
NVL(CL.ADDRESS1,' '),
NVL(CL.ADDRESS2,' '),
CL.POCO_POSTAL_CODE, NVL(CL.CITY,' '),
NVL(CL.AUTO_SURV_CODE,0),
CA.Col_Collector_Id
FROM CLIENT CL, CASES CA
WHERE CA.CL_CLIENT_ID = CL.CLIENT_ID ) a,
(SELECT NVL(REF_NO,' '), NVL(TO_CHAR(DATE_OF_JUDGEMENT,'rrmmdd'),' '),CA_CASE_ID
FROM CASE_INSTANCES
WHERE IN_INSTANCE_TYPE IN (1,8) AND
CA_CASE_ID = :current_case_id AND
PETITION_DATE = (SELECT MAX(PETITION_DATE)
FROM CASE_INSTANCES
WHERE IN_INSTANCE_TYPE IN (1,8)
AND CA_CASE_ID = :current_case_id
AND ROWNUM < 2
) b
WHERE a.case_id = b.ca_case_id(+)
Regards
K.Rajkumar
Similar Messages
-
Hi experts,
I need to join two queries but not sure how:
select id from test_table1;
select *
from table(f_function(null
,null
,1 -- the id
,sysdate);One query has IDs needed to run the second query. Is there a way to join those two?
The result should be all columns from test_table1 + all columns from f_function.
Best regards,
Igor
Edited by: Igor S. on Mar 8, 2013 5:18 AMHi,
Igor S. wrote:
select *
from test_table1,
table(
f_function(
null,
null,
id,
sysdate
select *
from test_table1,
table(
f_function(
null,
null,
id,
sysdate
) xyz
where test_table1.id = xyz.id
/So these two queries are the same?Try it and see.
You'll find that the 2nd one produces an error. But if you change it to
select *
from test_table1,
table(
f_function(
null,
null,
id,
sysdate
) -- No alias here
) xyz -- Alias here, instead
where test_table1.id = xyz.id
/Then, assuming f_function produces a column called id, it will work.
Whether it produces the same results or not depends on what the function returns, and whether either id is NULL.
If the id column that the function returns is the same as the id value that you pass to it, and is never NULL, then the 2 queries will produce the same results.
Either way, each row of test_table1 will be joined to each row that the function produces with the argument(s) from that row. The column names produced by the function and the values in those columns are determined by the function; they do not need to have anything in common with any table. In practice, a function like f_function will usually not return an column that is always identical to any of its inputs, since that value is already available from the input. -
Joining these these two queries (one regular and one grouped)
Hello
I have these two queries I would like to join, however the later is a grouped query how can I join it with the first query?
Has to be joined on EventId. The second query is a total table scan.
SELECT AH.EventID,
AH.TechnicalAddress, AH.AlarmAlias, AH.AlarmPath as [OrgAlarmPath], AH.AlarmCounter as AlarmCount, AH.EventDateTime as EventTime,
AH.[Priority], AH.AlarmMessage, AH.EventText, AH.CallListName, AH.AlarmReadDate as EndTime,
AH.alh_EventEndedUserRemark as [EndRemark] --, SUM(seconds) here, and AlarmSessions here
FROM AlarmHistory AH
WHERE (AH.HeartbeatAlarm = 0 OR AH.HeartbeatAlarm IS NULL) AND
((AH.CallListID IS NOT NULL) OR (AH.alh_IsForStatistics = 1)) AND
(NOT (AH.alh_t_EventSubCode is NULL or AH.AlarmReadByUserID is NULL))
ORDER BY AH.EventID DESC
SELECT ia.eventID, SUM(DATEDIFF(SECOND,ia.eventTime,r.eventTime)) AS seconds, COUNT(*) as AlarmSessions
FROM alarmHistoryLog ia
INNER JOIN alarmHistoryLog r
ON ia.EventId = r.EventId
AND r.EventTypeId = 2
AND r.EventSeq = (SELECT MIN(eventSeq) FROM alarmHistoryLog WHERE eventSeq > ia.EventSeq AND EventTypeId = 2)
WHERE ia.EventTypeId = 0
group by ia.EventId
order by EventId desc
HenryTry the below:
;with ctefirst as
SELECT AH.EventID,
AH.TechnicalAddress, AH.AlarmAlias, AH.AlarmPath as [OrgAlarmPath], AH.AlarmCounter as AlarmCount, AH.EventDateTime as EventTime,
AH.[Priority], AH.AlarmMessage, AH.EventText, AH.CallListName, AH.AlarmReadDate as EndTime,
AH.alh_EventEndedUserRemark as [EndRemark] --, SUM(seconds) here, and AlarmSessions here
FROM AlarmHistory AH
WHERE (AH.HeartbeatAlarm = 0 OR AH.HeartbeatAlarm IS NULL) AND
((AH.CallListID IS NOT NULL) OR (AH.alh_IsForStatistics = 1)) AND
(NOT (AH.alh_t_EventSubCode is NULL or AH.AlarmReadByUserID is NULL))
), ctesecond as
SELECT ia.eventID, SUM(DATEDIFF(SECOND,ia.eventTime,r.eventTime)) AS seconds, COUNT(*) as AlarmSessions
FROM alarmHistoryLog ia
INNER JOIN alarmHistoryLog r
ON ia.EventId = r.EventId
AND r.EventTypeId = 2
AND r.EventSeq = (SELECT MIN(eventSeq)
FROM alarmHistoryLog WHERE eventSeq > ia.EventSeq AND EventTypeId = 2)
WHERE ia.EventTypeId = 0
group by ia.EventId
Select A.*,B.seconds,B.AlarmSessions From ctefirst A
Inner join ctesecond B On A.EventId = B.EventID
Please mark this reply as answer if it solved your issue or vote as helpful if it helped.
[Blog] -
Whats the difference between these two queries ? - for tuning purpose
Whats the difference between these two queries ?
I have huge amount of data for each table. its takeing such a long time (>5-6hrs).
here whice one is fast / do we have any other option there apart from listed here....
QUERY 1:
SELECT --<< USING INDEX >>
field1, field2, field3, sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end)
FROM
tab1 inner join tab2 on condition1 inner join tab3 on condition2 inner join tab4 on conditon3
WHERE
condition4..10 and
GROUP BY
field1, field2,field3
HAVING
sum( case when field4 in (1,2) then 1 when field4 in (3,4) then -1 else 0 end) <> 0;
QUERY 2:
SELECT --<< USING INDEX >>
field1, field2, field3, sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0))
FROM
tab1, tab2, tab3, tab4
WHERE
condition1 and
condition2 and
condition3 and
condition4..10
GROUP BY
field1, field2,field3
HAVING
sum( decode(field4, 1, 1, 2, 1, 3, -1, 4, -1 ,0)) <> 0;
[pre]My feeling here is that simply changing join syntax and case vs decode issues is not going to give any significant improvement in performance, and as Tubby points out, there is not a lot to go on. I think you are going to have to investigate things along the line of parallel query and index vs full table scans as well any number of performance tuning methods before you will see any significant gains. I would start with the Performance Manual as a start and then follow that up with the hard yards of query plans and stats.
Alternatively, you could just set the gofast parameter to TRUE and everything will be all right.
Andre -
Can these two queries be combined
Is there a more eloquent way of joining the two tales to only
get those records that have more than one record. Instead of
writing two seperated queries, can one query achieve the
results?Could this also have been solved with one query by just doing
the following?
<cfquery name="get_mult_posn" datasource="#dsn#">
SELECT a.posn_id, a.pers_id, a.job_titl, frst_name,
mid_name, last_name
FROM posntable a, perstable b
WHERE a.pers_id = b.pers_id
</cfquery> -
These two queries return same data?
select * from voucher where (unit = 'TIA4M' or unit = 'TIAFM' or unit = 'TIAWM' or unit = 'TIATW' or unit = 'TIAPA' )
and invoice_dt >= TO_DATE('01/01/2006', 'MM/DD/YYYY')
select * from voucher where unit in ('TIA4M', 'TIAFM', 'TIAWM', 'TIATW', 'TIAPA')
and invoice_dt >= TO_DATE('01/01/2007', 'MM/DD/YYYY')
Also the first is much faster right?The first query is using a date of Jan 1, 2006. The second query is using a date of Jan 1, 2007.
Assuming that is a typo, the two queries are semantically identical. Since Oracle can easily transform an IN-list to a series of OR's, though, I would doubt that there would be any performance difference between them absent the 2006/2007 change.
Justin -
How do I join together these two queries?
Hi I have these queries:
select br_no, br_managersname from BRANCH order by br_managersname;
select sum(rent_endkms-rent_startkms) as "TOTAL KMS TRAVELLED" from RENTAL group by BR_NO having SUM(rent_endkms-rent_startkms) = (select MAX(sum(rent_endkms-rent_startkms)) from RENTAL group by BR_NO);
They each output their own tables, but I wanna join them together so they output as one table. Unfortunately, I really suck at joining tables. Can anyone help?Hmm... Not enought information again... Any way, let me consider br_no as the key between the two query. In that case i came up with this.
with query1
as
select br_no, br_managersname
from BRANCH order by br_managersname
query2
as
select br_no, sum(rent_endkms-rent_startkms) as total_kms_travelled
from RENTAL
group by BR_NO
having SUM(rent_endkms-rent_startkms) = (select MAX(sum(rent_endkms-rent_startkms))
from RENTAL
group by BR_NO)
select q1.bar_no, q1.br_managersname, q2.total_kms_travelled
from query1 q1
join query2 q2
on q1.br_no = q2.br_no -
Help me join these two scripts please!
hello, I have two statements
SELECT
--distinct
a.address_line3
,a.address_line4
,a.address_line5
,a.post_code
,a.tel_no
,l.claim_no
,lpad(row_number() OVER(ORDER BY l.claim_no), 6, '0') AS snum
,l.input_title
,l.input_surname
,l.INPUT_HOUSE_NO
,l.INPUT_BUILDING
,l.INPUT_FLAT
,l.input_address_line1
,l.input_address_line2
,l.input_address_line3
,l.input_address_line4
,l.input_post_code
,to_char(sysdate, 'MON YYYY') AS prntdate
,l.input_title AS input_title2
,l.input_surname AS input_surname2
,h.lpa_amt
,h.START_DATE
,h.elig_rate
,h.rate_rebate
,h.rr_amt
,h.lpa_applic
,h.lpa_amt AS lpa_amt2
,a.sho_name
FROM lpa_input l, lpa_address a, lpa_history h, lpa_credhist_ha c
wHERE a.aun_code = l.input_aun_code
AND l.claim_no = h.claim_no
AND h.claim_no = c.claim_no
and ent_seqno = (select max (ent_seqno) from lpa_history where claim_no = l.claim_no)
SELECT DISTINCT CLAIM_NO FROM LPA_HISTORY
WHERE DATE_created > '01/APR/2009' AND CLAIM_NO NOT IN
(select CLAIM_NO from lpa_notifications)
ORDER BY CLAIM_NOCan i put this select statment at the end of the first script??
ThanksHi try this
SELECT
distinct
a.address_line3
,a.address_line4
,a.address_line5
,a.post_code
,a.tel_no
,l.claim_no
,lpad(row_number() OVER(ORDER BY l.claim_no), 6, '0') AS snum
,l.input_title
,l.input_surname
,l.INPUT_HOUSE_NO
,l.INPUT_BUILDING
,l.INPUT_FLAT
,l.input_address_line1
,l.input_address_line2
,l.input_address_line3
,l.input_address_line4
,l.input_post_code
,to_char(sysdate, 'MON YYYY') AS prntdate
,l.input_title AS input_title2
,l.input_surname AS input_surname2
,h.lpa_amt
,h.START_DATE
,h.elig_rate
,h.rate_rebate
,h.rr_amt
,h.lpa_applic
,h.lpa_amt AS lpa_amt2
,h.CLAIM_NO
,a.sho_name
FROM lpa_input l, lpa_address a, lpa_history h, lpa_credhist_ha c
WHERE a.aun_code = l.input_aun_code
AND l.claim_no = h.claim_no
AND h.claim_no = c.claim_no
AND ent_seqno = (select max (ent_seqno) from lpa_history where claim_no = l.claim_no)
AND DATE_created > '01/APR/2009' AND CLAIM_NO NOT IN
(select CLAIM_NO from lpa_notifications)
ORDER BY h.CLAIM_NONOTE: not tested. -
Can anyone join these two into one?
<?if:1=1?>Page 1<?end if?><?if:1!=1?>Other Page<?end if?>
<?fo:page-number?>
I want to replace the first 1 with the page number function...
Please help me, I'n running out of time.Hi Tim,
I don't think it is important which functionallity I want to achieve. My real question is: can I use a function (like <?fo:page-number?> in a function (like <?if:?>).
Kind regards,
Corné -
select itm.inventory_item_id "Item#",itm.segment1,itm.description,qty.SUBINVENTORY_CODE as SHI,
sum(qty.primary_transaction_quantity) "On Hand Qty"
from MTL_ONHAND_QUANTITIES_DETAIL qty,
mtl_system_items itm
WHERE itm.inventory_item_id=qty.inventory_item_id
and itm.ORGANIZATION_ID=qty.ORGANIZATION_ID
and qty.SUBINVENTORY_CODE IN ('ITC-8888', 'ITC-9999')
and trunc(qty.last_update_date) <=:P_DATE_FROM
AND trunc(SYSDATE) >=:P_DATE_TO
group by qty.SUBINVENTORY_CODE,itm.inventory_item_id,itm.segment1,itm.description;
select distinct SUBSTR( kmt.tag_number, 1,6), fa.model_number from kfupm_mcr_tag kmt, fa_additions fa
where kmt.TAG_NUMBER =fa.TAG_NUMBER ;
and fa.model_number is not null;
union all is not working.
Regards
ArifuddinWhile using the set operators, to match the number of columns in the SELECT list you can make use of NULL as:
SELECT COL_NAME1,COL_NAME2,COL_NAME3
FROM TAB_NAME1
UNION
SELECT COL_NAME1,COL_NAME2,NULL
FROM TAB_NAME2The columns in the both SELECT lists should be same and also the datatype. The resultant of the query will be the columns of first SELECT list (column aliases) -
I have these below queries. How do I join these 3 queries into a single query?
1st query:
SELECT TOP(1) @tmpOnlineCat = ac.AlertCatID
FROM alert.AlertCategory ac
WHERE ac.FkAlertID = 2
AND ac.FkAlertTypeID = 3
2nd query
SELECT TOP(1) @tmpOfflineCat = ac.AlertCatID
FROM alert.AlertCategory ac
WHERE ac.FkAlertID = 3
AND ac.FkAlertTypeID = 3
3rd query
INSERT INTO item.ItemOnlineOfflineAlertCategory
VALUES
@tmpPkItemID,
@tmpOfflineCat,
@tmpOnlineCat
mayooran99I think this is all what you need!
INSERT INTO item.ItemOnlineOfflineAlertCategory
SELECT @tmpPkItemID,
MAX(CASE WHEN FkAlertID = 2 THEN AlertCatID END) AS tmpOnlineCat,
MAX(CASE WHEN FkAlertID = 3 THEN AlertCatID END) AS tmpOfflineCat
FROM alert.AlertCategory
WHERE FkAlertTypeID = 3
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
_1st query_
select
(CASE WHEN SUBSTR(R1.RA_NO,1,3)= 'NRA' THEN 'Damansara Uptown One Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,3)= 'ORA' THEN 'Damansara Uptown Two Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,3)= 'VRA' THEN 'Damansara Uptown Realty Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,3)= 'URA' THEN 'Uptown Elite Sdn. Bhd.'
when SUBSTR(R1.RA_NO,1,3)= 'WRZ' THEN 'U5 Management Corporation Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,2)= 'FR' THEN 'See Hoy Chan Facilities Management Sdn.Bhd.' END) Landlord
,TO_CHAR(C1.COLL_DTE,'RRRRMM') MONTH1
,SUM(C2.TRN_AMT) UPTO_31
, SUM(CASE WHEN to_char(C1.COLL_dte) BETWEEN to_date(:P_FROM_DATE,'dd.mm.yyyy') AND '16-'||to_date(:P_TO_DATE,'dd.mm.yyyy') THEN C2.TRN_AMT END) UPTO_15
from ra1 R1, COLLECT1 C1 , COLLECT2 C2
where
(to_char(C1.COLL_dte) between to_date(:P_FROM_DATE,'dd.mm.yyyy') AND to_date(:P_TO_DATE,'dd.mm.yyyy'))
and (SUBSTR(R1.RA_NO,1,2)= 'FR' or SUBSTR(R1.RA_NO,1,3) in ('NRA' ,'ORA','VRA','URA','WRZ'))
AND R1.RA_NO = C2.INV_NO
AND C2.COLL_NO = C1.COLL_NO
GROUP BY
(CASE WHEN SUBSTR(R1.RA_NO,1,3)= 'NRA' THEN 'Damansara Uptown One Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,3)= 'ORA' THEN 'Damansara Uptown Two Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,3)= 'VRA' THEN 'Damansara Uptown Realty Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,3)= 'URA' THEN 'Uptown Elite Sdn. Bhd.'
when SUBSTR(R1.RA_NO,1,3)= 'WRZ' THEN 'U5 Management Corporation Sdn. Bhd.'
WHEN SUBSTR(R1.RA_NO,1,2)= 'FR' THEN 'See Hoy Chan Facilities Management Sdn.Bhd.' END)
,TO_CHAR(C1.COLL_DTE,'RRRRMM')
_2query_
select sum(decode(substr(ra_no,1,7),'NRA'
||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) NRA
,sum(decode(substr(ra_no,1,7),'VRA'
||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) VRA
,sum(decode(substr(ra_no,1,7),'ORA'
||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) ORA
,sum(decode(substr(ra_no,1,7),'FR'
||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) FR
,sum(decode(substr(ra_no,1,7),'WRZ'
||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) WRZ
,sum(decode(substr(ra_no,1,7),'URA'
||to_char(to_date(:P_FROM_DATE,'dd.mm.yyyy'),'yymm'),tot_amt,0)) URA
from RA1
above are the two queries i need to join these two queries by naming the second query column name as total .1st query output is ----------
LOCATION MONTH1 UPTO_31 UPTO_15
U5 Management Corporation Sdn. Bhd. 201001 15250 8900
Uptown Elite Sdn. Bhd. 201001 3000 1500
See Hoy Chan Facilities Management Sdn.Bhd. 201001 917115.45 584876.5
Damansara Uptown Two Sdn. Bhd. 201001 757277.45 495362.95
Damansara Uptown One Sdn. Bhd. 201001 881558.65 404872.45
Damansara Uptown Realty Sdn. Bhd. 201001 321675.8 150508.6
2nd query output is -------
NRA ORA VRA URA WRZ FR
2323.31 95945 34367.8 34267 4343 343
Now what i need is
LOCATION MONTH1 UPTO_31 UPTO_15 TOTAL
U5 Management Corporation Sdn. Bhd. 201001 15250 8900 2323.31
Uptown Elite Sdn. Bhd. 201001 3000 1500 95945
See Hoy Chan Facilities Management Sdn.Bhd. 201001 917115.45 584876.5 34367.8
Damansara Uptown Two Sdn. Bhd. 201001 757277.45 495362.95 34267
Damansara Uptown One Sdn. Bhd. 201001 881558.65 404872.45 4343
Damansara Uptown Realty Sdn. Bhd. 201001 321675.8 150508.6 343above is the clear picture what i need , i don't know how to do it please help me
Edited by: user9093689 on Feb 21, 2010 8:06 PM -
How can we make an outer join (+) between 2 Queries
in the data model, i have 2 queries
i.e
Q_master and Q_detail
i want to make a data link between
these two queries and
also make an outer join between these
two queries(i.e. to display all the detail
records, whether they have details or not)
please reply is it possible ?
if yes then how?
plz write.
[email protected]
nullHello,
Left outer join behavior is what you get by default with a link between two queries in Reports.
If you want a full outer join behavior, you'll need to create a third query that selects the detail records that have no corresponding master, and also create an extra layout region to display them in as a default group left or group above won't pick up these extra records.
If you want right outer join behavior, you'll need to put in a summary in the master query that counts the rows in the detail, and then put in a format trigger in the master repeating frame that suppresses printing when there are no detail records. And you'll also need the third query and layout section as in the full outer join case.
Regards,
The Oracle Reports Team --skw -
Query 1 show me a list of users, each user should tell me how many orders, how many row, and total amount they placed <b>for a certain date</b>.
Query 2 show me again a list of user, each user should me how many orders and how many row they placed <b>excluding that date above that are still open</b>.
I would like these two queries to show on one report. Is it possible?
Query 1:
SELECT COUNT(DISTINCT T0.UserSign) AS 'Today_order',
COUNT(T1.PickStatus) AS 'Today_row', SUM(T1.Price *
T1.OpenQty) AS 'Today_amount' FROM [dbo].[RDR1] T1
INNER JOIN [dbo].[ORDR] T0 ON T1.DocEntry = T0.DocEntry
WHERE <b>T0.DocDate = CONVERT(DATETIME, '20051109', 112)</b>
AND T1.OpenQty > 0
Query 2:
SELECT COUNT(DISTINCT T0.UserSign) AS 'Other_order',
COUNT(T1.PickStatus) AS 'Other_row' FROM [dbo].[RDR1]
T1 INNER JOIN [dbo].[ORDR] T0 ON T1.DocEntry =
T0.DocEntry WHERE T1.OpenQty > 0 AND <b>T0.DocDate <>
CONVERT(DATETIME, '20051109', 112)</b>Hi Laura,
It's probably easiest to use temporary tables or a cursor for this query.
This code works for me (in SQL Query Analyzer and SBO):
set nocount on
create table #users (UserSign int, UserName nvarchar(30))
create table #today (UserSign int, Today_row int, Today_amount numeric(15, 2))
create table #other (UserSign int, Other_row int)
insert into #users
select T0.USERID, T0.U_NAME from OUSR T0
insert into #today
SELECT DISTINCT T0.UserSign AS 'Today_order',
COUNT(T1.PickStatus) AS 'Today_row', SUM(T1.Price *
T1.OpenQty) AS 'Today_amount'
FROM [dbo].[RDR1] T1
INNER JOIN [dbo].[ORDR] T0 ON T1.DocEntry = T0.DocEntry
WHERE T0.DocDate = CONVERT(DATETIME, '20051109', 112)
AND T1.OpenQty > 0
GROUP BY T0.UserSign
insert into #other
SELECT DISTINCT T0.UserSign AS 'Other_order',
COUNT(T1.PickStatus) AS 'Other_row' FROM [dbo].[RDR1]
T1 INNER JOIN [dbo].[ORDR] T0 ON T1.DocEntry =
T0.DocEntry WHERE T1.OpenQty > 0 AND T0.DocDate <>
CONVERT(DATETIME, '20051109', 112)
GROUP BY T0.UserSign
set nocount off
select T0.UserSign, T0.UserName, isnull(T1.Today_row, 0) as Today_row,
isnull(T1.Today_amount, 0) as Today_amount,
isnull(T2.Other_row, 0) as Other_row
from
#users T0 left outer join #today T1 on T0.UserSign = T1.UserSign
left outer join #other T2 on T0.UserSign = T2.UserSign
drop table #users
drop table #today
drop table #other
I've added the user name from the OUSR table to make the query a bit easier to understand.
Hope this helps,
Owen -
How to combine two queries in one EXCEL
hi i got one requirement
i got one excel sheet from user which contains two report s(hoe we know whether it is worknook or not) of 2011 data and now user wants 2012 data .now i icluded jan 2012 to dec 2012 in two reports and sent to user.But user is asking these two reports want to see in one sheet.
so how can i proceed: if i go for work book how can i include these two reports in workbook and here my doubt is if i create a workbook based on these two querie which name i have to give user.Please help me out on the same.
Regards,
Madhu.Hi Madhu
Run one query. Click on a empty space in the excel
From the BEx Design Toolbar -
>Insert Analysis Grid -
> Right click on the Design Item
Edit the DataProvider.....You can ran same or different query with selection.
Save the result
Check this link for detail....I am also searching for something with screenshot
Regards
Anindya
Edited by: Anindya Bose on Feb 14, 2012 3:04 AM
Maybe you are looking for
-
Query to extract HTML tag with data
Hi All, I have a string. '<HTML><HEAD>THIS IS HEAD.</HEAD><BODY>THIS IS BODY.<P>THIS IS P1.</P>NIMISH<P>THIS IS P2.</P></BODY></HTML>' I want to extract a html tag including its opening & closing tab with data as if i say P1 then the output should be
-
Unable to respond to Calendar Invitations
I seem to be running into a strange bug and am curious if anyone has seen this before. On all of my devices (iPhone, iPad, and iMac), I am unable to respond to a Calendar event. On the iOS devices, when I tap on a response, it displays in the calend
-
Not able to post depreciation in the new co code
Hi I am trying to post the Depreciation using AFAB into a newly created Co Code for the first time. But the system throws the below error asking me to post to the last month of the previous year. You can only post in new year after closing the previo
-
MiniDP to HDMI issues after upgrading to 10.6.5.
With 10.6.4, the only issue I was hoping to have fixed was adding the overscan slider adjustment that the mini has, but 10.6.5 completely broke my miniDP out. When plugging in the adapter, one of two things happens... either my tv doesn't recognize t
-
System variable issue on outgoing payment
Hi, I encounter the error "Printing Error:Invalid variable number (RPT -6300) (Field: F_397) Variable '202' [Message 200-38]" on my outgoing payment. This only happen when i select "Account" option, for "vendor" or "customer" option is fine. This is