Query Jump with Navigation ( Sub query need to show same Navigation )
Hi All.
We have 4 BEx queries in our Dashboard Web Template and each table web items shows 10 rows and remaining with Scorll.
For Printing ,we have created a query jump for each BEx Query ( same copy query) that shows all the rows detail.
When i tried to jump from Orginial Dashboard ( From Specific table/Bex Query) with drill down <b>( Plant by Material )</b> , the jump query is not showing the same drill down but it showing the default rows <b>( Plant as per query rows</b>).
SAP has suggested us its possible to do Query Jump with Navgiation that shows the same drill down path (navigation) in Sub Query as well.
Am unable to find how to configure that , did search in OSS / Other Forumns But there were no postings on this.
For me there is no Settings in RSBBS (or) SPRO and tried the Web Address Jump as well to pass the Drill Down Status (or) Navigation. May be iam not looking at right place. We are at 3.1x
We found some limitations with SAP recommended web printing ( we dont need to discuss about that as per our requirement ), and our users like the Query Jump printing as which we working on now.
Please inform if this can be possible, if so how.
Thanks
Martin Mouli
Thanks for reply Bhanu.
Its not like just Plant by Material.
I would like to do my slicing & dicing on Navigational block with any combinations ( Customer by Plant by Material )
When i do query jump from My Original Web Table , my jump query need to show the same drill down ( Customer by Plant by Material)but its showing only Material. ( Which is a default row in sub query)
To show the same navigation in jump query as well, right now am doing drill down again in jump query as well. Its time waste to repeat the same drill down steps in sub query.
By default my Jump Query has Material as row and We will show Plant & Customer on Demand (free characteristics)
Please inform if more information required.
Regards
Martin Mouli
Similar Messages
-
Can someone please help me with a sub query question?
I need to list a 3rd party contract and then a list of students who belong to that contract.
On the students segment of the listing I need to show students with student id, name, total credit hours,
total amount spent on tuition, total amount spent on books and total amount spent on misc.
This code has a query for the contract information and I get that just fine.
Then it has a query that gives me total credit hours and that works fine
then it has a query that gives me total amount spent on tuition and that works fine
but
when I add the next query to get total amount spent on books I get only the information for the contract, I don't get student stuff anymore.
I would really appreciate any guidance that you could give.
Thanks in advance, Bob Hohulski
DECLARE
l_conn utl_TCP.connection;
v_filehandle utl_file.file_type;
v_output varchar2(1000);
v_contract_id varchar2(9);
v_contract_addr1 varchar2(30);
v_contract_addr2 varchar2(30);
v_contract_city varchar2(20);
v_contract_stat varchar2(03);
v_contract_zip varchar2(10);
v_contract_name varchar2(60);
v_student_id varchar2(09);
v_student_first_name varchar2(15);
v_student_mid_name varchar2(15);
v_student_last_name varchar2(60);
v_last_out varchar2(20);
v_student_detail_code varchar2(04);
v_student_amount number(12,2);
v_student_ref_number varchar2(09);
v_credit_hrs number(7,2);
v_tuition_amount number(12,2);
v_books_amount number(12,2);
v_misc_amount number(12,2);
v_total_for_student number(12,2);
v_current_student varchar2(09);
v_sftregs_pidm varchar2(09);
v_tbraccd_pidm varchar2(09);
CURSOR c_sel_contract IS
SELECT DISTINCT spriden_id, spriden_last_name,
spraddr_street_line1, spraddr_street_line2,
spraddr_city, spraddr_stat_code, spraddr_zip
FROM spriden, spraddr
-- WHERE spriden_id = '&Enter_Id'
where spriden_id = 'T10474666'
AND spriden_pidm = spraddr_pidm
AND SPRIDEN_CHANGE_IND IS NULL;
CURSOR c_sel_student IS
SELECT DISTINCT spriden_id, spriden_first_name, spriden_mi, spriden_last_name,
sftregs_credit_hr,
tbraccd_amount,
sftregs_pidm,
tbraccd_pidm
FROM spriden, tbraccd, tbbcstu, sftregs
WHERE 559220 = tbbcstu_contract_pidm
AND spriden_pidm = tbraccd_pidm
AND spriden_pidm = tbbcstu_stu_pidm
AND spriden_pidm = sftregs_pidm
AND (sftregs_pidm, sftregs_credit_hr) IN
(SELECT DISTINCT sftregs_pidm, SUM(sftregs_credit_hr)
FROM sftregs, tbbcstu, spriden
WHERE sftregs_term_code = '201010'
AND sftregs_pidm = tbbcstu_stu_pidm
AND sftregs_pidm = spriden_pidm
GROUP BY sftregs_pidm)
AND (tbraccd_pidm, tbraccd_amount) IN
(SELECT DISTINCT tbraccd_pidm, SUM(tbraccd_amount)
-- tuition
FROM tbraccd, tbbcstu, spriden
WHERE tbraccd_term_code = '201010'
AND (tbraccd_detail_code = 'TU01' OR
tbraccd_detail_code = 'TU02' OR
tbraccd_detail_code = 'TU03' OR
tbraccd_detail_code = 'TU04')
AND tbraccd_pidm = tbbcstu_stu_pidm
AND tbraccd_pidm = spriden_pidm
GROUP BY tbraccd_pidm)
--this code works up to this point
--when I add the next query I get nothing
AND (tbraccd_pidm, tbraccd_amount) IN
(SELECT tbraccd_pidm, SUM(tbraccd_amount)
books
FROM tbraccd, tbbcstu
WHERE tbraccd_term_code = '201010'
AND (tbraccd_detail_code = 'BKSU' OR
tbraccd_detail_code = 'BKCH')
AND tbraccd_pidm = tbbcstu_stu_pidm
GROUP BY tbraccd_pidm, tbraccd_amount)
--AND (tbraccd_pidm, tbraccd_amount) IN
-- (SELECT tbraccd_pidm, SUM(tbraccd_amount)
-- misc
-- FROM tbraccd, tbbcstu
-- WHERE tbraccd_term_code = '201010'
-- AND tbraccd_pidm = tbbcstu_stu_pidm
-- AND (tbraccd_detail_code = 'AUNA' OR
-- tbraccd_detail_code = 'OTPB')
-- GROUP BY tbraccd_pidm, tbraccd_amount)
--ORDER BY tbraccd_pidm, spriden_first_name, spriden_mi, spriden_last_name,
-- tbbcstu_sponsor_ref_number, sftregs_credit_hr;
ORDER BY tbraccd_pidm;
BEGIN
v_filehandle := utl_file.fopen(location => 'UTLFILE_MISAP9',
filename => 'ban_matrix.dat',
open_mode => 'w',
max_linesize => 32767);
OPEN c_sel_contract;
LOOP
DBMS_OUTPUT.PUT_LINE('looping');
FETCH c_sel_contract INTO v_contract_id, v_contract_name,
v_contract_addr1, v_contract_addr2,
v_contract_city, v_contract_stat,
v_contract_zip;
EXIT WHEN c_sel_contract%NOTFOUND;
v_output :=
nvl(rpad(v_contract_id,9),rpad(' ',9)) ||
' ' ||
nvl(rpad(v_contract_name,60),rpad(' ',60));
utl_file.put_line(v_filehandle,v_output);
v_output :=
nvl(rpad(v_contract_addr1, 30),rpad(' ',30)) ||
' ' ||
nvl(rpad(v_contract_addr2, 30),rpad(' ',30));
utl_file.put_line(v_filehandle,v_output);
v_output :=
nvl(rpad(v_contract_city, 20), rpad(' ',20)) ||
' ' ||
nvl(rpad(v_contract_stat, 3), rpad(' ',3)) ||
' ' ||
nvl(rpad(v_contract_zip, 10), rpad(' ',10));
utl_file.put_line(v_filehandle,v_output);
utl_file.new_line(v_filehandle);
OPEN c_sel_student;
LOOP
FETCH c_sel_student into v_student_id, v_student_first_name, v_student_mid_name,
v_student_last_name,
v_credit_hrs,
v_tuition_amount,
v_sftregs_pidm,
v_tbraccd_pidm;
-- v_books_amount, v_misc_amount;
EXIT WHEN c_sel_student%NOTFOUND;
v_last_out := substr(v_student_last_name, 1, 20);
v_output :=
nvl(rpad(v_student_id, 09),rpad(' ',09)) ||
' ' ||
nvl(rpad(v_student_first_name, 15),rpad(' ',15)) ||
nvl(rpad(v_student_mid_name, 15),rpad(' ',15)) ||
nvl(rpad(v_last_out, 20),rpad(' ',20)) ||
' ' ||
nvl(rpad(v_student_ref_number, 09),rpad(' ',09)) ||
' ' ||
v_credit_hrs ||
' ' ||
v_tuition_amount ||
-- v_books_amount ||
-- ' ' ||
-- v_misc_amount;
utl_file.put_line(v_filehandle,v_output);
END LOOP;
END LOOP;
--EXCEPTION
--WHEN OTHERS THEN
-- DECLARE
-- err_msg VARCHAR2(100);
-- BEGIN
-- err_msg := 'ERR- '||SUBSTR(SQLERRM, 1,100);
-- - utl_file.put_line(v_filehandle,err_msg);
--END;
utl_file.fclose(v_filehandle);
CLOSE c_sel_contract;
CLOSE c_sel_student;
--END AR_MATRIX_PROC;
END;run this original query
SELECT DISTINCT spriden_id,
spriden_first_name,
spriden_mi,
spriden_last_name,
sftregs_credit_hr,
tbraccd_amount,
sftregs_pidm,
tbraccd_pidm
FROM spriden, tbraccd, tbbcstu, sftregs
WHERE 559220 = tbbcstu_contract_pidm
AND spriden_pidm = tbraccd_pidm
AND spriden_pidm = tbbcstu_stu_pidm
AND spriden_pidm = sftregs_pidm
AND (sftregs_pidm, sftregs_credit_hr) IN (SELECT DISTINCT sftregs_pidm, SUM(sftregs_credit_hr)
FROM sftregs, tbbcstu, spriden
WHERE sftregs_term_code = '201010'
AND sftregs_pidm = tbbcstu_stu_pidm
AND sftregs_pidm = spriden_pidm
GROUP BY sftregs_pidm)
AND (tbraccd_pidm, tbraccd_amount) IN (SELECT DISTINCT tbraccd_pidm, SUM(tbraccd_amount)
-- tuition
FROM tbraccd, tbbcstu, spriden
WHERE tbraccd_term_code = '201010'
AND (tbraccd_detail_code = 'TU01' OR
tbraccd_detail_code = 'TU02' OR
tbraccd_detail_code = 'TU03' OR
tbraccd_detail_code = 'TU04')
AND tbraccd_pidm = tbbcstu_stu_pidm
AND tbraccd_pidm = spriden_pidm
GROUP BY tbraccd_pidm)
AND (tbraccd_pidm, tbraccd_amount) IN (SELECT tbraccd_pidm, SUM(tbraccd_amount) books
FROM tbraccd, tbbcstu
WHERE tbraccd_term_code = '201010'
AND (tbraccd_detail_code = 'BKSU' OR
tbraccd_detail_code = 'BKCH')
AND tbraccd_pidm = tbbcstu_stu_pidm
GROUP BY tbraccd_pidm, tbraccd_amount)
ORDER BY tbraccd_pidm;then run this sub-query:
SELECT tbraccd_pidm, SUM(tbraccd_amount) books
FROM tbraccd, tbbcstu
WHERE tbraccd_term_code = '201010'
AND (tbraccd_detail_code = 'BKSU' OR
tbraccd_detail_code = 'BKCH')
AND tbraccd_pidm = tbbcstu_stu_pidm
GROUP BY tbraccd_pidm, tbraccd_amount)see if you have a matching tbraccd_pidm and tbraccd_amount between the two results. -
Query is executed although sub-query is error?
Hi everyone,
I have a problem want to explained.
My sub-query show an error if it's executed alone: "ORA-00904: invalid column name"
SELECT id FROM table_A WHERE field1 = 'exam' (field1 is not exist)
But when execute with:
SELECT * FROM table_B WHERE id IN (SELECT id FROM table_A WHERE field1 = 'exam')
it's ok, although we don't have any data filtered. I don't known the reason why? Can anyone explain this?
Thanks a lot!I think you're looking at something like this...
SQL> select deptno from emp where dname = 'SALES';
select deptno from emp where dname = 'SALES'
ERROR at line 1:
ORA-00904: "DNAME": invalid identifier
SQL> select deptno from dept where deptno in (select deptno from emp where dname in 'SALES');
DEPTNO
30
SQL> select deptno from dept where deptno in (select deptno from emp where emp.dname in 'SALES');
select deptno from dept where deptno in (select deptno from emp where emp.dname in 'SALES')
ERROR at line 1:
ORA-00904: "EMP"."DNAME": invalid identifier
SQL> ed
Wrote file afiedt.buf
1* select deptno from dept where deptno in (select deptno from emp where dept.dname in 'SALES')
SQL> /
DEPTNO
30In this example, "DNAME" doesn't exist in the emp table, but in the second query it seems to work. However what it's really doing is referencing the "DNAME" column of the outer query. This is proved in the third and fourth query by prefixing the DNAME column with the EMP and DEPT table names to explicitly say where we are expecting the column to come from. -
Help understanding simple query trace with 35,000 "query subcube" events
No matter WHAT query I issue against my cube, I'm finding thousands of query subcube events against an unexpected , I assume it's a partition.
Even for the simplest possible query SELECT FROM <CUBE>, which for this cube would return the measure [MRN Distinct Count], a trace reveals 35,000 query subcube events against a partition (?) called "<server>.Medical Home.MedHome.Lab Orders
With Results" which is NOT the partition that holds that [MRN Distinct Count] measure.
I can't figure out why this object is being queried so many times for queries completely unrelated to it. I believe this performance degradation is somewhat new...so I have been trying to think of what may have been added to the cube recently.
I recently added KPIs and calculated sets & members that DO draw from that Lab Orders With Results object...would calculated members or KPI's cause this kind of problem? I thought that they were all pre-calculated @ processing?
Thanks for any insight you can provide
Here's a summary of the profiler trace on the query SELECT FROM <CUBE>
Event Desc
# of Events
ObjectPath
Duration
Query Begin
1
NULL
0
Query Cube Begin
1
<server>.Medical Home.MedHome
0
Query Subcube Verbose
11
<server>.Medical Home.MedHome.Fact Dx 2
189
Query Dimension
7
<server>.Medical Home.Dim Person
0
Query Subcube Verbose
35650
<server>.Medical Home.MedHome.Lab Orders With Results
13856
Serialize Results Begin
1
<server>.Medical Home.MedHome
0
Serialize Results Current
4
<server>.Medical Home.MedHome
0
Query Subcube Verbose
5
<server>.Medical Home.MedHome.Dim Person
0
Serialize Results Current
1
<server>.Medical Home.MedHome
0
Serialize Results End
1
<server>.Medical Home.MedHome
0
Query Cube End
1
<server>.Medical Home.MedHome
40919
Query End
1
NULL
41059
PaulRedBirdRising - my cube had several dynamic calculated sets in it. As I recall several of those sets included slices on that one particular dimension that was being queried so many times. For me it was sets that compiled populations of people
with particular lab result values, so that lab result partition was queried thousands of times for ANY query, even simple ones like SELECT FROM [CUBE].
To be precise, I actually had calculated sets interacting with calculated measures - for example, one of the offending calculated sets was really this series of calculations:
-CALC SET 1: define calculated set of diabetic patients
-CALC MEASURE 1: define calculated measure for most recent lab test result of a particular lab test - which included a slice on the dimension I found being queried thousands of times.
-DYNAMIC calculated set: FILTER(CALC SET1, CALC MEASURE 1 <= x)
So as soon as I switched that dynamic set to a STATIC set my queries began executing in a reasonable amount of time and those query subcube events were no longer issued in the thousands. I feel like i've heard that FILTER performs poorly but didn't
know of any alternatives to achieve what we needed.
hope this helps...I can't say I know for sure what unforseen impact(s) switching to static sets has had yet. Dynamic seemed like the way to go but the performance hit was just too drastic.
Paul -
I am trying to improve this query? Is there a better way to write the query and get the same results. I hate the fact that I am querying a table 3 times.
Select statement
WITH t1 AS
(SELECT 101 AS ID
, 1 AS a
, NULL AS b
, 5 AS c
FROM DUAL
UNION ALL
SELECT 102
, NULL
, 2
, 5
FROM DUAL
UNION ALL
SELECT 101
, 3
, 5
, 7
FROM DUAL
UNION ALL
SELECT 101
, 1
, NULL
, NULL
FROM DUAL)
, t2 AS
(SELECT 101 AS ID
, 1 AS x
FROM DUAL
UNION ALL
SELECT 101
, 5
FROM DUAL
UNION ALL
SELECT 102
, 5
FROM DUAL
UNION ALL
SELECT 102
, 2
FROM DUAL)
SELECT *
FROM t1
WHERE t1.ID = 101
AND ( t1.a IS NULL
OR t1.a IN (SELECT t2.x
FROM t2
WHERE t2.ID = t1.ID))
AND ( t1.b IS NULL
OR t1.b IN (SELECT t2.x
FROM t2
WHERE t2.ID = t1.ID))
AND ( t1.c IS NULL
OR t1.c IN (SELECT t2.x
FROM t2
WHERE t2.ID = t1.ID))Output:
ID A B C
101 1 5
101 1 -- ThanksThis is an interesting question.
WITH t1 AS
(SELECT 101 AS ID, 1 AS ColA, NULL AS ColB, 5 AS ColC FROM DUAL UNION ALL
SELECT 102, NULL, 2, 5 FROM DUAL UNION ALL
SELECT 101, 3, 5, 7 FROM DUAL UNION ALL
SELECT 101, 5,99,99 FROM DUAL UNION ALL
SELECT 101, 1, NULL, NULL FROM DUAL)
, t2 AS
(SELECT 101 AS ID , 1 AS ColX FROM DUAL UNION ALL
SELECT 101 , 5 FROM DUAL UNION ALL
SELECT 102 , 5 FROM DUAL UNION ALL
SELECT 102 , 2 FROM DUAL UNION ALL
SELECT 101 , 3 FROM DUAL UNION ALL
SELECT 101 , 5 FROM DUAL UNION ALL
SELECT 101 , 7 FROM DUAL)
select *
from t1 a
where ID = 101
and exists(select 1
from t2 b
where b.ID = a.ID
having (a.ColA is null or max(case when b.ColX = a.ColA then 1 else 0 end) = 1)
and (a.ColB is null or max(case when b.ColX = a.ColB then 1 else 0 end) = 1)
and (a.ColC is null or max(case when b.ColX = a.ColC then 1 else 0 end) = 1));
ID ColA ColB ColC
101 1 null 5
101 3 5 7
101 1 null nullFurthermore,
We can use below alternative solution.
Below alternative solution is used Boolean arithmetic (http://www.allaboutcircuits.com/vol_4/chpt_7/2.html)
WITH t1 AS
(SELECT 101 AS ID, 1 AS ColA, NULL AS ColB, 5 AS ColC FROM DUAL UNION ALL
SELECT 102, NULL, 2, 5 FROM DUAL UNION ALL
SELECT 101, 3, 5, 7 FROM DUAL UNION ALL
SELECT 101, 5,99,99 FROM DUAL UNION ALL
SELECT 101, 1, NULL, NULL FROM DUAL)
, t2 AS
(SELECT 101 AS ID , 1 AS ColX FROM DUAL UNION ALL
SELECT 101 , 5 FROM DUAL UNION ALL
SELECT 102 , 5 FROM DUAL UNION ALL
SELECT 102 , 2 FROM DUAL UNION ALL
SELECT 101 , 3 FROM DUAL UNION ALL
SELECT 101 , 5 FROM DUAL UNION ALL
SELECT 101 , 7 FROM DUAL)
select *
from t1 a
where ID = 101
and exists(select 1
from t2 b
where b.ID = a.ID
having max(case when b.ColX = a.ColA or a.ColA is null then 1 else 0 end)
* max(case when b.ColX = a.ColB or a.ColB is null then 1 else 0 end)
* max(case when b.ColX = a.ColC or a.ColC is null then 1 else 0 end) = 1);This thread is dealt logic which is "max(case when P(X) then 1 else 0 end) = 1" is for some X:P(X).
And this thread deals alike question.
Re: Select only records with same Id
I mentioned alike logic in this thread.
Re: Newbie: Simple select with 'IN ALL'
I recommend these articles.
http://www.dbazine.com/ofinterest/oi-articles/celko5
http://www.dbazine.com/ofinterest/oi-articles/celko18 -
Sub totals with a sub query!!
Hi All,
I want to build a query with the following columns from the table 'address_details':
name, address,total,a_total, b_total, c_total, d_total
where total is a sum of a_total, b_total, c_total and d_total.
And where a_total, b_total, c_total and d_total are individual sum of a particular type.
Can you please help me to write a query for this.
Thanks in adv.
bh_t_76This?
SQL> select * from test;
NAME ADDRESS VALUE TYPE
xx xxxxxxxxx 50 a
xx xxxxxxxxx 50 a
xx xxxxxxxxx 100 a
xx xxxxxxxxx 500 b
xx xxxxxxxxx 50 c
xx xxxxxxxxx 100 c
xx xxxxxxxxx 50 d
xx xxxxxxxxx 50 d
xx xxxxxxxxx 1000 d
9 rows selected.
SQL> select name,address,sum(value) total,
2 sum(decode(type,'a',value)) tot_a,
3 sum(decode(type,'b',value)) tot_b,
4 sum(decode(type,'c',value)) tot_c,
5 sum(decode(type,'d',value)) tot_d
6 from test
7 group by name,address;
NAME ADDRESS TOTAL TOT_A TOT_B TOT_C TOT_D
xx xxxxxxxxx 1950 200 500 150 1100 -
Hi there,
I have written a stored procedure but It was throwing an error like this
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
update FMM.DEF_BID_STATUS
set FILENAME =(select FILENAME
from FMM.DEF_BID_STATUS BS2
where SITE_ID in(select min(SITE_ID) from FMM.SITES)
and BS1.BID_STATUS_ID = BS2.BID_STATUS_ID)
FROM FMM.DEF_BID_STATUS BS1 where SITE_ID = 1
Can anyone please check what is wrong in this.
Thanks for your helpTry the below:
update FMM.DEF_BID_STATUS
set FILENAME =(selectFILENAME
from FMM.DEF_BID_STATUS BS2
where SITE_ID in(select min(SITE_ID) from FMM.SITES)
and BS1.BID_STATUS_ID = BS2.BID_STATUS_ID and BS2.SITE_ID = BS1.SITE_ID)
FROM FMM.DEF_BID_STATUS BS1 where SITE_ID = 1 -
Filter query with sub query using Dropdown box
Dear Community,
I have 2 queries
1. Main Query with 2 fields: Project | Project value
2. Sub Query with 2 fields: Project group | Project
Project group can be belonging to number of projects and project can be belong to number of project group (Many to Many).
My customer wants the main query will open without any filtering.
When I choose project group from WAD dropdown box, the main query will filtering all the projects that belong to the project group.
I create WAD; define dropdown box as sub query, and Analysis as main query.
In the dropdown box I choose "data binding" char and create command "set selection state by binding" (project to project) but it doesnu2019t work.
I also try to do this by Replacement Path in the main query, but the variable requires the attribute will be ready for input.
Thanks a lot
YanivI am not sure about your comments on replacement path variable. Without having tried it, here is what I would have attempted:
The main query needs to use a replacement path variable for Project that is replaced by the results of the sub-query. Sub-query would have a regular input variable for project group. (as a quick test, if you had one analysis item for main query with variable input enabled, it should prompt you to enter Project group).
Now the drop-down needs to be associated with a javascript function. The javascript function needs to implement command "Set variable state" for the main query data provider to selected value of the drop-down.
The drop-down should be associated with the sub-query data provider, just used to populate the list of values in drop-down. -
Need to include duplicate records in sub query
Hi All,
I am using the following query and i am getting error message that your sub query return dupliate records and throwing error. Actually i need these duplicate records for my report. I want to get records for
whole year like
JAN FEB MARCH .. ... ...
and idea how i can achieve this task and my query is as follows
select pmnum
,SITEID,
(select description from locations where pm.location = locations.location and pm.siteid=locations.siteid) as site,
(select description from commodities where commodities.commodity= pm.commoditygroup) as workcategory,
description, (select wonum from workorder where workorder.pmnum = pm.pmnum
and targstartdate < '2013-02-01') as jan,
(select wonum from workorder where workorder.pmnum = pm.pmnum and
workorder.status<>'CAN' and targstartdate >= '2013-02-01' and
targstartdate < '2013-03-01') as feb,
(select wonum from workorder where workorder.pmnum = pm.pmnum and
workorder.status<>'CAN' and targstartdate >= '2013-03-01' and
targstartdate < '2013-04-01') as mar
(select name from companies where companies.company = pm.vendor) as contractor
from pm where ((PM.siteid = 'AAA'))Subqueries in the SELECT column list must return a scalar value (single row, single column). If you need multiple rows returned, use a join instead. But you need to consider what will happen when more than one row is returned by more than one
of the joins because these are correlated with the pm table row but not each other. For example, let's say you have a single row returned from "pm" matching 5 sites and 3 workcategories. This will result in 15 rows being returned for the single
pm row.
Below is an untested example.
SELECT
pmnum
,SITEID
,locations.description as site
,commodities.description as workcategory
,pm.description
,workorder_jan.wonum AS jan
,workorder_feb.wonum AS feb
,workorder_mar.wonum AS mar
,companies.name AS contractor
FROM dbo.pm
LEFT JOIN dbo.locations ON pm.location = locations.location
AND pm.siteid=locations.siteid
LEFT JOIN dbo.commodities ON commodities.commodity = pm.commoditygroup
LEFT JOIN dbo.workorder AS workorder_jan ON workorder_jan.pmnum = pm.pmnum
AND workorder_jan.targstartdate < '2013-02-01'
LEFT JOIN dbo.workorder AS workorder_feb ON workorder_feb.pmnum = pm.pmnum
AND workorder_feb.status <> 'CAN'
AND workorder_feb.targstartdate >= '2013-02-01'
AND workorder_feb.targstartdate < '2013-03-01'
LEFT JOIN dbo.workorder AS workorder_mar ON workorder_mar.pmnum = pm.pmnum
AND workorder_mar.status <> 'CAN'
AND workorder_mar.targstartdate >= '2013-03-01'
AND workorder_mar.targstartdate < '2013-04-01'
LEFT JOIN dbo.companies ON companies.company = pm.vendor
WHERE pm.siteid = 'AAA';
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
Outter-Join with requirement for sub-query
I am working on a view that needs to return 1 record per payment date within the primary payment table.
Part of the information that is to be returned in this row comes from a date-controlled table containing superannuation information. This data may or may not be present, requiring an outer-join. The final problem is that there may be multiple rows in this superannuation table requiring me to retrieve the record with the most recent start date, prior to the payment date. This is where I'm breaking down currently as I cannot outer-join to a sub-query.
I had an idea that I could create an inline view of the superannuation table with 1 row for each of the last 365 days (The reports that will be built off the view are always run within 1-2 months of the payment date), with the date and either the required information or blanks if it did not exist. This would avoid me requiring an outer-join as I could just join on the payment date to the date in the inline query and return whatever data was there.
I'm pretty sure I should be able to do this with analytics rather than creating a date table, by restricting the rows to 365, then havign a column that is effectively the previous column - 1. Unfortunately I'm fairly new to analytics and find the Oracle documentation hard to decipher.
Can anyone help with this or perhaps suggest an alternate solution?please don't do that. that's the most pathetic way generate rows. all_objects is a very nasty view, and oracle reserves the right to merge the view into the rest of your query, making performance less than you had hoped for. how about this instead:
select ...
from (
select trunc(sysdate-rownum+1) super_date
from dual
connect by level < = 365 ) dates,
your_table_here
where dates.super_date = your_column (+)
... -
I have SSRS parametarized report in that one data set have repeated values with query parameter . but while am mapping that query
parameter to report parameter i need to pass distinct values. How can i resolve thisHi nancharaiah,
If I understand correctly, you want to pass distinct values to report parameter. In Reporting Service, there are only three methods for parameter's Available Values:
None
Specify values
Get values from a query
If we utilize the third option that get values from a dataset query, then the all available values are from the returns of the dataset. So if we want to pass distinct values from a dataset, we need to make the dataset returns distinct values. The following
sample is for your reference:
Select distinct field_name from table_name
If you have any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Please suggest a select query / sub query with out using any subprograms or
source table: Three columns ORIGIN, DESTINATION,MILES
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Melbourne Sydney 1000
Brisbane Sydney 1000
Perth Darwin 4000
Sydney Brisbane 1000
out put :Three columns ORIGIN, DESTINATION,MILES
Duplicate routes are to be ignored so the output is
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Brisbane Sydney 1000
Perth Darwin 4000
Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Hi,
user9368047 wrote:
... Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Why? If the most efficient way to get the results you want involves using a function, why wouldn't you use it?
Here's one way, without any functions:
SELECT a.*
FROM source_table a
LEFT OUTER JOIN source_table b ON a.origin = b.destination
AND a.destination = b.origin
AND a.miles = b.miles
WHERE b.origin > a.origin -- Not b.origin > b.origin
OR b.origin IS NULL
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
Edited by: Frank Kulash on Nov 6, 2012 7:39 PM
Corrected WHERE clause after MLVrown (below) -
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer. -
Joining with sub query not working
Hi
I am new with these complex queries. I am trying to join a sub query to a query as below;
SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo, (SELECT EventID, SUM(Total) FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) AS Total
FROM tblEvents AS Events1 LEFT OUTER JOIN
tblClients ON Events1.ClientID = tblClients.ID
WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate
HAVING (Events1.InvoiceBatch = 5212)
ORDER BY tblClients.Company
I am getting these two errors;
Msg 8120, Level 16, State 1, Line 2
Column 'tblEvents.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 116, Level 16, State 1, Line 2
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
What am I missing?
Thanks
RegardsSELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo,Total
FROM tblEvents AS Events1 LEFT OUTER JOIN
tblClients ON Events1.ClientID = tblClients.ID
LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
ON sb.EventID = Events1.ID
WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate,Total
HAVING (Events1.InvoiceBatch = 5212)
ORDER BY tblClients.Company
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
Says;
Msg 4104, Level 16, State 1, Line 5
The multi-part identifier "Events1.ID" could not be bound.
on
LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
Regards -
The issue with using the multiple columns sub-query in WHERE clause
Hi All,
my database version is 10.2.
the problem i am trying to deal with is that when I use multiple column sub-query in the WHERE clause of the SELECT statement, the actual row number returned from the sub-query is different from the whole statement.
And what I found is that, whenever there is NULL in any of those columns returned from the SUB-QUERY, the outer query will just return NULL for that whole row.
Here is an example:
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t;
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT NULL 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10
select * from EMP where (EMPNO, ENAME, job, MGR, HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 If I specifically deal with the NULL situations for the columns which might return NULL, I can get the result right.
select * from EMP where (EMPNO, ENAME, job, NVL(MGR,-1), HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from EMP
intersect
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT null 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 the problem is that, I feel this is a very lame way of handling it.
So, I wonder or am asking if there is any better or standard way to do it?
any help would be highly appreciated.
ThanksHi,
As you discovered, INTERSECT treats NULL as a value, but IN does not.
What you did with NVL is one way to handle the situation. If there was a chance that any of the columns could be NULL, then you might prefer something like this:
select *
from EMP
where ( EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
) in (
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from emp
intersect
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from t
);This assumes that you can identify some string (I used '~') that never occurs in the strings in these tables.
This is implicitly converting the NUMBERs. That's usually not a good thing to do. but explicitly converting them would make this even more tedious.
You should explicitly convert any DATEs to strings, however. Depending on your default format, and your data, you might get away with implicit conversions even for DATEs, but don't bet on it.
If you had to do this often, you might consider writing a user-defined function:
delimited_string (empno, ename, job, mgr, hiredate, sal, deptno) would return a string like
'7839~KING~PRESIDENT~~17-NOV-1981~5000~10'
This will make the coding easier, but beware: it will make the execution slower.
Maybe you are looking for
-
HELP! MY BLACKBERRY8310 DOESN'T WORK
I typed in the wrong password on my blackberry8310 10 times and now my blackberry won't turn on or work. Does anybody know what I need to do or buy in order to get it working? I appreciate it. Thanx!!
-
I have one exchange server with fourteen server databases. One these server databases is housing 15 mailbox databases (user mailboxes databases) of these fifteen mailbox DB's all have the same search problem in both the inbox and sent items. They all
-
Zoom in-out and rotation in trackpad doesn't work in iPhoto and Aperture. Any solution?
Zoom in-out and rotation in trackpad doesn't work in iPhoto and Aperture. Any solution?
-
PC Permissions issues with 10.5 server
We are having some permission problems for our PC users. Here is what typically happens. User is working within a job folder. Within this job folder are a couple of other folders to organize the job parts. The user will modify some of the files and t
-
iPhoto was working just fine the other day. When I launched it earlier, it said "no photos" and did not prompt me to find my library. I tried moving the iPhoto Library to a different location and relaunching but was not prompted to choose my library.