Combining two Queries
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
Similar Messages
-
Confused on syntax-combine two queries
I have two queries that I'm trying to combine, but can't figure out how to combine them ... successfully!?! The first query is pretty simple in that I'm looking at several fields from two different tables, no big deal.
The second query calculates the years, months, days between two dates that are used in the first query. I'm stumped on how to combine the queries so that they place nice with each other and return results.
Here's the first query ...
select
RTRIM(RTRIM(vpi.LastName) + ', ' + RTRIM(ISNULL(vpi.FirstName,''))) Employee,
convert(varchar,vpi.FromEffectiveDate,101) PositionStart,
convert(varchar,vpi.ToEffectiveDate,101) PositionChange,
convert(varchar,vpi.PositionStartDate,101) PositionStartDate,
vpi.PositionReason, vpi.PositionCode, vpc.PositionCodeDescription
from vhrl_positioninfo vpi
inner join position_codes vpc on vpi.PositionCode = vpc.PositionCode
Here's the second query ...
select
[Age] = convert(varchar, [Years]) + ' Years ' +
convert(varchar, [Months]) + ' Months ' +
convert(varchar, [Days]) + ' Days', *
from
select
[Years] = case when BirthDayThisYear <= Today
then datediff(year, BirthYearStart, CurrYearStart)
else datediff(year, BirthYearStart, CurrYearStart) - 1
end,
[Months]= case when BirthDayThisYear <= Today
then datediff(month, BirthDayThisYear, Today)
else datediff(month, BirthDayThisYear, Today) + 12
end,
[Days]= case when BirthDayThisMonth <= Today
then datediff(day, BirthDayThisMonth, Today)
else datediff(day, dateadd(month, -1, BirthDayThisMonth), Today)
end,
Birth = convert(varchar(10) ,Birth, 121),
Today = convert(varchar(10), Today, 121)
from
select BirthDayThisYear =
case when day(dateadd(year, datediff(year, BirthYearStart, CurrYearStart), Birth)) <> day(Birth)
then dateadd(day, 1, dateadd(year, datediff(year, BirthYearStart, CurrYearStart), Birth))
else dateadd(year, datediff(year, BirthYearStart, CurrYearStart), Birth)
end,
BirthDayThisMonth =
case when day(dateadd(month, datediff(month, BirthMonthStart, CurrMonthStart), Birth)) <> day(Birth)
then dateadd(day, 1, dateadd(month, datediff(month, BirthMonthStart, CurrMonthStart), Birth))
else dateadd(month, datediff(month, BirthMonthStart, CurrMonthStart), Birth)
end,
from
select BirthYearStart = dateadd(year, datediff(year, 0, Birth), 0),
CurrYearStart = dateadd(year, datediff(year, 0, Today), 0),
BirthMonthStart = dateadd(month, datediff(month, 0, Birth), 0),
CurrMonthStart = dateadd(month, datediff(month, 0, Today), 0),
from
select birth = convert(datetime, fromeffectivedate) ,
Today = case when convert(datetime, toeffectivedate) = '3000-01-01'
THEN convert(datetime, convert(int,getdate()))
else vpi.toeffectivedate
end
from vHRL_PositionInfo vpi inner join position_codes vpc
on vpi.PositionCode = vpc.PositionCode
) aaaa
) aaa
) aa
)a
Here's the sample data ...
vpi table ...
LastName FirstName FromEffectDate ToEffectDate PosStartDate PosReason PosCode
Doe John 2001-10-15 3000-01-01 10-15-2001 Transfer OperPack
Smith Tom 1994-11-28 2001-10-14 1994-11-28 New Hire OperDC
vpc table ...
PosCode PosDescription
OperPack Pack Line Operator
OperDC Descaler Operator
This is what the results should look like ...
John, Doe 2001-10-15 3000-01-01 10-15-2001 Transfer OperPack Pack Line Operator 6 Years 11 Months 16 Days
John, Doe 1994-11-28 2001-10-14 1994-11-28 New Hire OperDC Descaler Operator 6 Years 6 Months 19 Days
I know the date calculation piece adds 5 additional fields to the end, but they are not needed for the final report. Any help would be greatly appreciated! Thank you! JenaYour query suggests you're not using Oracle. Please post in your relevant database forum.
-
Combining two queries in a join
SQL> desc messages;
Name Null? Type
MESSAGEID NOT NULL NUMBER
TITLE NOT NULL VARCHAR2(50)
AUTHOR VARCHAR2(20)
BODY NOT NULL VARCHAR2(4000)
BOARD NUMBER
THREAD NOT NULL NUMBER
DATE_CREATED NOT NULL DATE
SQL>
I'm trying to combine both queries outlined below. The first query
selects the very first message created in the messages table. It does
this by checking whether thread=0. If it is that means it started a message.
The second query checks the number of replies to the thread above.
The replies to the above message
will have a thread value the same as the above messageid.
That is how a reply is identified.
I am trying to do both queries in one so that the output has
the starting message first with the name
of the person who created the new thread(author), date_created, etc....below that
then is the
number of replies to the message,the author of each reply and the date....
I'm using oracle 8i so i cant use the join key word...
any ideas would be appreciated.
----selects message that started thread---------------------------------
select b.title,b.boardid,m.messageid,m.title,m.author,
m.date_created,m.body
from messages m, boards b where b.boardid=m.board and m.thread=0 and b.boardid='198'
and m.messageid='241';
Thread title Author Starting message Last post
Austrailia noel Austrailia 04/01/2005 21:22:35
-----selects replies to the above message-----------
select author,date_created,body
from messages
where board=198 and thread=241;
AUTHOR DATE_CREATED BODY
noel 05-JAN-05 Oz is played on clay
noel 05-JAN-05 Oz played on grass
noel 05-JAN-05 Oz played on grassThis is a duplicate post of the following thread:
URGENT: combining two sql statements -
I have two queries and I would like to output the results as
one and sort by Name ASC
Any help would be great thanksEither use union in your SQL query or use Coldfusion to
combine exisitng queries and create a new query resultset.
Something like this:
<CFQUERY NAME="getDetailsQuery1"
DATASOURCE="#DSNNAME#">
SELECT * FROM getDetailsA
</CFQUERY>
<CFQUERY NAME="getDetailsQuery2"
DATASOURCE="#DSNNAME#">
SELECT * FROM getDetailsB
</CFQUERY>
<CFQUERY NAME="getDetails" DBTYPE="query">
SELECT * FROM getDetailsQuery1
UNION
SELECT * FROM getDetailsQuery2
ORDER BY Name ASC
</CFQUERY>
Hope this helps!
Cheers / Manu. -
Combining two queries in one..
Hi,
Can someone tell me how to combine follwoing two queries in one so that it will increase performance..
SELECT single PLNNR from AFKO
into T1
WHERE AUFNR = '007200000100'.
SELECT single STATU from PLKO
into T2
WHERE PLNNR = T1.using subqueries it is possible
select single statu from plko into t2 where plnnr in (select single plnnr from afko where aufnr eq '007200000100').
read about subqueries at this link...
http://help.sap.com/saphelp_erp2004/helpdata/en/dc/dc7614099b11d295320000e8353423/frameset.htm
regards,
PJ -
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 -
How can I combine two queries ? QoQ does not work
I have one query where I just count the total qty coming in per month, something like:
<cfquery name="qryIn" datasource="dbname">
select count(orderNO) as totalIN,month
where status = "IN"
group by month
</cfquery>
I then have a second query to count the total qty going out per month
<cfquery name="qryOut" datasource="dbname">
select count(orderNO) as totalOut,month
where status = "OUT"
group by month
</cfquery>
I then use QoQ to combine both:
<cfquery="qryTotal" dbtype="query">
select
totalIN,
totalOUT
from qryIN,qryOUT
where qryIN.month = qryOUT.month
</cfquery>
The problem I am running into is that QoQ does not allow LEFT JOIN, so that if the month is in one query but not the other, it will not pick up that record. And that is throwing off my counts.
How can I combine both queries, and bypass QoQ to get a qty IN and qty Out value, per month ? and, for example, if qty in exists for one month and qty Out does not exists for that month, then qty Out will be zero for that month.
I need this data to plot a chart.
Thanks for any help provided.Do it in a single query to your database. Here is part of it.
select month
, sum(case when when status = "IN" then 1 else 0 end) total_in -
How to Combine two queries into One
Hi Gurus,
SQL> select * from v$version;
BANNER
Oracle Database 10g Release 10.2.0.4.0 - 64bit Production
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL>
I have following two queries. How I can convert these two queries into one with the same result ?
Q1
SELECT id,vdate,vendorname,venddate,vid
FROM VENDOR
WHERE processid=32
AND venddate is null
AND vid in(select vid from view_vid where type='PDX')
AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=55)
AND (id,vdate) in (select id,vidate from market_data where marketed_date is null)
AND id not in (select id from location)
Q2
SELECT id,vdate,vendorname,venddate,vid
FROM VENDOR
WHERE processid=20
AND venddate is null
AND vid in(select vid from view_vid where type='PBX')
AND (id,vdate) not in (select id,vdate from vkfl_is where task_id=40)
AND (id,vdate) in (select id,vidate from market_data where region_date is null)
AND id not in (select id from location)
I can UNION these two queries, but, is there any way I can write a single query with which gives me same result as above two queries?
Any help would be highly appreciated
Thanks in advanceHi,
You can do something like this, which will be more efficient than a UNION:
SELECT id, vdate, vendorname, venddate, vid
FROM vendor
WHERE ( ( -- Conditions that apply only to q1
processid = 32
AND vid IN (SELECT vid FROM view_vid WHERE type = 'PDX')
AND (id,vdate) NOT IN ( SELECT id, vdate
FROM vkfl_is
WHERE task_id = 55
AND (id,vdate) IN ( SELECT id, vidate
FROM market_data
WHERE marketed_date IS NULL
OR ( -- Conditions that apply only to q2
processid = 20
AND vid IN (SELECT vid FROM view_vid WHERE type = 'PBX')
AND (id,vdate) NOT IN ( SELECT id, vdate
FROM vkfl_is
WHERE task_id = 40
AND (id,vdate) IN ( SELECT id, vidate
FROM market_data
WHERE region_date IS NULL
-- The remaining conditions apply to both q1 and q2
AND venddate IS NULL
AND id NOT IN (SELECT id FROM location)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Combining two queries into one query if possible
Hi there. I would like, if possible, to somehow combine the queries 1) and 2) into a single query.
1) select distinct user_id from system_user_sessions;
This query returns all unique users from the indicated table.
2) select count(session_id) from system_user_sessions where user_id = "each user_id returned from 1)";
This query will return, for each distinct user_id, the number of sessions involving that user. In other words I would like to return the user_id of each user together with the number of session_ids involving that user.
any ideas? JoeI assume you are looking for something like this:
select count(session_id)
from system_user_sessions
where user_id in ( select distinct user_id
from system_user_sessions
);HTH
Ghulam -
Create a view with combine two queries
Hi I have two sql queries but just the where condition is just differed But i need a separate coulmn in one view. The data is comming from same table. I need to make two different column like qry 1 fullname, qry2.full name like that
first query
Select
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name as Full_Name,
SF.Stu_id ,
SF.stu_cur_schl,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4) as M_Year,
D.MONTH_DESC as MonthName,
LD.LOC_DISTRICT_SHRT_DESC as DistrictCode,
LD.LOC_DISTRICT_DESC as DistrictName,
LD.LOC_KEY ,
LD.LOC_DESC ,
TF.STU_ID as M_SID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1 as StudentPerformance ,
TF.CHAR_BCKT_2 as TestStatus,
TF.CHAR_BCKT_3 as StudentPerformanceClean,
TF.INT_BCKT_1 as Score1,
TF.INT_BCKT_2 as Score2,
TF.INT_BCKT_4 as CPI
From
Student_Fact SF,
EPMS_PROD.TEST_SUMMARY_FACT2 TF,
TEST_DIM TD,
LOCATION_DIM LD,
EPMS_PROD.DATE_DIM D
where
SF.SIMS_PERIOD_ID=(select max(SF.SIMS_PERIOD_ID) from Student_Fact SF) and
SF.STU_ID=TF.STU_ID and
SF.SIMS_SCHOOL_YEAR=substr(TF.DATE_SID, 1, 4) and
--TD.TEST_ID in(1,4) and TD.SUB_TEST_ID =100 and
TD.TEST_SID=TF.Test_sid and
LD.LOC_SID=TF.Loc_sid and
D.DATE_SID=TF.DATE_SID and
--TF.Stu_id in('1040822404','1091432903') and
TD.SUBJECT_ID<>0 and
TF.CHAR_BCKT_2<>' '
group by
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name,
SF.Stu_id,
SF.stu_cur_schl,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4),
D.MONTH_DESC,
TF.STU_ID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1,
TF.CHAR_BCKT_2,
TF.CHAR_BCKT_3,
TF.INT_BCKT_1,
TF.INT_BCKT_2,
TF.INT_BCKT_4,
LD.LOC_DISTRICT_SHRT_DESC,
LD.LOC_DISTRICT_DESC,
LD.LOC_KEY,
LD.LOC_DESC
second query
Select
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name as SIMS_Full_Name,
SF.Stu_id ,
SF.stu_cur_schl,
SF.STU_REPORTING_ORG_CODE,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4) as M_Year,
D.MONTH_DESC as MonthName,
LD.LOC_DISTRICT_SHRT_DESC as DistrictCode,
LD.LOC_DISTRICT_DESC as DistrictName,
LD.LOC_KEY as SchoolCode,
LD.LOC_DESC as SchoolName,
LD.LOC_TYPE_CODE,
LD.LOC_TYPE_DESC,
TF.STU_ID as M_SID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1 as StudentPerformance ,
TF.CHAR_BCKT_2 as TestStatus,
TF.CHAR_BCKT_3 as StudentPerformanceClean,
TF.INT_BCKT_1 as Score1,
TF.INT_BCKT_2 as Score2,
TF.INT_BCKT_4 as CPI
From
Student_Fact SF,
EPMS_PROD.TEST_SUMMARY_FACT2 TF,
TEST_DIM TD,
LOCATION_DIM LD,
EPMS_PROD.DATE_DIM D
where
--SF.SIMS_PERIOD_ID=(select max(SF.SIMS_PERIOD_ID) from Student_Fact SF) and
SF.STU_ID=TF.STU_ID and
SF.SIMS_SCHOOL_YEAR=substr(TF.DATE_SID, 1, 4) and
--TD.TEST_ID in(1,4) and TD.SUB_TEST_ID =100 and
TD.TEST_SID=TF.Test_sid and
LD.LOC_SID=TF.Loc_sid and
D.DATE_SID=TF.DATE_SID and
--TF.Stu_id in('1040822404','1091432903') and
TD.SUBJECT_ID<>0 and
TF.CHAR_BCKT_2<>' ' and
--LD.LOC_TYPE_CODE in (6, 13)
SF.SIMS_COL_PERIOD in ('Mar', 'EOY') and
SF.REAS_FOR_ENROLL_CODE in ('06', '07')
group by
SF.Stu_Last_Name || ', ' || SF.stu_First_Name || ' ' || SF.stu_Middle_Name,
SF.Stu_id,
SF.stu_cur_schl,
SF.STU_REPORTING_ORG_CODE,
SF.REAS_FOR_ENROLL_CODE,
SF.REAS_FOR_ENROLL_DSC,
SF.SIMS_SCHOOL_YEAR,
SF.SIMS_COL_PERIOD,
SF.SIMS_PERIOD_ID,
substr(TF.DATE_SID, 1, 4),
D.MONTH_DESC,
TF.STU_ID,
TD.GRADE,
TD.SUBJECT_ID,
TD.SUBJECT_NAME,
TF.CHAR_BCKT_1,
TF.CHAR_BCKT_2,
TF.CHAR_BCKT_3,
TF.INT_BCKT_1,
TF.INT_BCKT_2,
TF.INT_BCKT_4,
LD.LOC_DISTRICT_SHRT_DESC,
LD.LOC_DISTRICT_DESC,
LD.LOC_KEY,
LD.LOC_DESC,
LD.LOC_TYPE_CODE,
LD.LOC_TYPE_DESC
Can you please help how do do it.
Thanks
RamYes. it is okay when i use Union and create some dummy column in each of the query and do it. But here other people thinks performance may be a issue. Now they r telling try with function or something.
So thats what i am thinking how to resolve in best way... They strongly suggest using function.
is it possible to do it in function?
Than ks
Ram -
How to combine two queries?
Can you help to combine these two categories so that I can have dynamic pivot table ?
Thank you,
IF OBJECT_ID('Temp') IS NOT NULL
DROP TABLE Temp
select 'Referrals Received' AS CategoryType,
'A' AS CategorySort,
cn.Cntry_Definition as Cntry,
COUNT(*) AS Cnt,
SUM(SUM(1)) OVER () AS Total
INTO Temp
from WRAPSIST0.dbo.tblindividual i
inner join WRAPSIST0.dbo.tblcase c on c.case_guid = i.case_guid
inner join WRAPSIST0.dbo.tblCountry CN on CN.Cntry_Code=c.Cntry_CodeLocation
inner join WRAPSIST0.dbo.tblfiscalyear fy on case_createdate between fy_startdate and fy_enddate
where fy_year = '2014' and casear_code <> 'du' and c.CaseP_Code<>'sv'
GROUP BY cn.Cntry_Definition
order by cntry asc
DECLARE @CountryList varchar(8000),@SQL varchar(max)
SELECT @CountryList= STUFF((SELECT ',[' + Cntry + ']' FROM Temp FOR XML PATH('')),1,1,'')
SET @SQL = 'SELECT CategoryType,' + @CountryList + ',Total FROM Temp t
PIVOT(SUM(Cnt) FOR Cntry IN (' + @CountryList + '))p'
EXEC(@SQL)
IF OBJECT_ID('Prescr') IS NOT NULL
DROP TABLE Prescr
select 'Prescreen Completed' AS CategoryType,
'B' AS CategorySort,
cn.Cntry_Definition as Cntry,
COUNT(*) AS Cnt,
SUM(SUM(1)) OVER () AS Total
INTO Prescr
FROM ReportStatistician.dbo.vwEventLog_LatestPSI_SCH t
inner join WRAPSIST0.dbo.tblIndividual i on i.Ind_GUID=t.Ind_GUID
inner join WRAPSIST0.dbo.tblCase C on C.Case_GUID=i.Case_GUID
inner join WRAPSIST0.dbo.tblNationality N on N.Nat_Code=i.Nat_Code
inner join WRAPSIST0.dbo.tblCountry CN on CN.Cntry_Code=c.Cntry_CodeLocation
inner join WRAPSIST0.dbo.tblfiscalyear fy on t.EventLog_EffectiveDate between fy_startdate and fy_enddate
where fy_year = '2014' and c.PreS_Code='com'
GROUP BY cn.Cntry_Definition
order by cntry asc
--DECLARE @CountryList varchar(8000),@SQL varchar(max)
SELECT @CountryList= STUFF((SELECT ',[' + Cntry + ']' FROM Prescr FOR XML PATH('')),1,1,'')
SET @SQL = 'SELECT CategoryType,' + @CountryList + ',Total FROM Prescr t
PIVOT(SUM(Cnt) FOR Cntry IN (' + @CountryList + '))p'
EXEC(@SQL)
CREATE TABLE #final
CategoryType varchar(50),
CategorySort char(1),
cntry char(20),
Total int
select CategoryType, cntry, Total
from #final
order by CategorySort
Erdal HuzmeliThe result of the query looks as following;
CategoryType
Kuwait
Lebanon
Turkey
United Arab Emirates
Yemen
Total
Referrals Received
1
2
3
4
5
CategoryType
Kuwait
Lebanon
Turkey
United Arab Emirates
Yemen
Total
Prescreen Comleted
6
7
8
9
10
I want the query to show the following result if it possible?
CategoryType
Kuwait
Lebanon
Turkey
United Arab Emirates
Yemen
Total
Referrals Received
1
2
3
4
5
Prescreen Completed
6
7
8
9
10
Thank you,
Erdal Huzmeli -
Combine two queries to Update a table in single query.
I need to update a table in a stored procedure in following manner:
IF p_status = 'FAILED' THEN
UPDATE pms_table
SET status = p_status
WHERE quote_id = p_quote_id
IF p_status = 'COMPLETED' THEN
UPDATE pms_table
SET status = p_status
WHERE quote_id = p_quote_id
How to combine above two queried in single query having same fuctionality.
Regards,
AgrawalVUPDATE pms_table
SET status = p_status
WHERE quote_id = p_quote_id
and p_status in ('FAILED','COMPLETED'); -
How to combine two queries using Web application Designer
Hello experts...
This should be a simple request.
I have two existing queries that I simply want to display on the same template. What is the best way to do this?
To add more complexity to it, if there is a result value that I want to pull from each of them, how can this be done so that I can add the results of the two into one total?
Any help that you can provide is greatly appreciated. ThanksHi,
Displaying the existing queries on the same template is very simple... Drag and drop to web items... for ex we will drag and drop two analysis web item...
Create 2 data providers and assign it to the web items... each dataprovider is in turn assigned to two existing queries...
I am not sure about the result value to be pulled from each of them...
Regards,
Kishore -
Basically what the query is doing, is counting the number of times the speed is over 106. The second query is adding up the distance traveled while going over a speed of 106. Is it possible to add these queries together??
select
count("speed") as "speedOver106",
"trek_id" as "speed_Trek_Id"
from "QAMASTER"."cust_positions"
where "speed" > 106
and "date_time" between to_date('09/01/2006', 'MM/DD/YYYY') and to_date('09/25/2006', 'MM/DD/YYYY')
and "operator_id" in (2)
group by "trek_id"
SELECT
p."trek_id", SUM(next_odometer-p."odometer") distance
from
SELECT
t."trek_id", t."odometer",
LEAD(t."odometer") OVER (PARTITION BY t."trek_id" ORDER BY t."odometer") next_odometer
FROM QAMASTER."cust_positions" t
where t."date_time" between to_date('09/01/2006', 'MM/DD/YYYY') and to_date('09/25/2006', 'MM/DD/YYYY')
and "speed" > 106
and "operator_id" in (2)
) p
GROUP BY p."trek_id"A count(*) in second query will do:
SELECT
p."trek_id", SUM(next_odometer-p."odometer") distance,
count(*) as "speedOver106"
from
SELECT
t."trek_id", t."odometer",
LEAD(t."odometer") OVER (PARTITION BY t."trek_id" ORDER BY t."odometer") next_odometer
FROM QAMASTER."cust_positions" t
where t."date_time" between to_date('09/01/2006', 'MM/DD/YYYY') and to_date('09/25/2006', 'MM/DD/YYYY')
and "speed" > 106
and "operator_id" in (2)
) p
GROUP BY p."trek_id" -
Hi,Please can any one help me how to combine the following two queries...
Query 1
SELECT distinct GCC.segment1,GCC.segment2,GCC.segment3,GCC.segment4,GCC.segment5,
GCC.segment6, DECODE(gcc.segment6,NULL,'',SUBSTR(apps.gl_flexfields_pkg.get_description_sql( gcc.chart_of_accounts_id,6,gcc.segment6),1,40))
DETAILS, sum(gje.accounted_dr) BUDGET_2014
FROM gl_je_lines gje, gl_code_combinations gcc
WHERE gje.code_combination_id(+)=gcc.code_combination_id
and je_header_id in (select je_header_id from gl_je_headers where
BUDGET_VERSION_ID in (select Bv.budget_version_id from gl_budget_versions Bv , gl_balances bal where BUDGET_NAME = 'BUDGET 2014_2' and actual_flag= 'B'))
and gcc.segment3 between 3100000000 and 3199999999 and gcc.segment2 =31
group by GCC.segment1,GCC.segment2,GCC.segment3,GCC.segment4,GCC.segment5,
GCC.segment6, DECODE(gcc.segment6,NULL,'',SUBSTR(apps.gl_flexfields_pkg.get_description_sql
(gcc.chart_of_accounts_id,6,gcc.segment6),1,40))
Query 2
SELECT distinct GCC.segment1,GCC.segment2,GCC.segment3,GCC.segment4,GCC.segment5,
GCC.segment6, DECODE(gcc.segment6,NULL,'',SUBSTR(apps.gl_flexfields_pkg.get_description_sql( gcc.chart_of_accounts_id,6,gcc.segment6),1,40))
DETAILS,sum(gje.accounted_dr) BUDGET_2011
FROM gl_je_lines gje, gl_code_combinations gcc
WHERE gje.code_combination_id(+)=gcc.code_combination_id
and je_header_id in (select je_header_id from gl_je_headers where
BUDGET_VERSION_ID in (select Bv.budget_version_id from gl_budget_versions Bv , gl_balances bal where BUDGET_NAME = '2011 BUDGET' and actual_flag= 'B'))
and gcc.segment3 between 3100000000 and 3199999999 and gcc.segment2 =31
group by GCC.segment1,GCC.segment2,GCC.segment3,GCC.segment4,GCC.segment5,
GCC.segment6, DECODE(gcc.segment6,NULL,'',SUBSTR(apps.gl_flexfields_pkg.get_description_sql
(gcc.chart_of_accounts_id,6,gcc.segment6),1,40))fermusic said...
"use I/O plugin in the Master 1-2 Output ... you will be able to route the signal to 3-4... or wherever you need.... just Bypass I/O plugin to return at 1-2 OUTs"
Thank you!
That's exactly how it works.
With the output assigned to 3-4 and input to 1-2, toggling the Bypass button switches the output.
And I don't have to replicate processors on the output 3-4 bus.
Very cool.
Cheers.
Maybe you are looking for
-
Adobe Photoshop CS3 crashing at open file screen
Hi all I've searched online but can't find a relative discussion or solution. I have Adobe Photoshop CS3. My system is Windows 7 and it's 64-bit (that's about as far as my hardware/technical knowledge goes...). The problem has only started happening
-
This is only my second project using Director (MX2004) - and I am having a problem with AVI Video playback. Normally I create some buttons and when a user selects a button I jump to a marker and play a video. So I dont have to account for all of the
-
How to make a file explorer work under certain conditions
Good afternoon, I have built a VI that is basically a file explorer that lets you import data to another application, when a button is clicked, you can navigate throught the directories of your pc searching for a txt file to import and plot some ghra
-
Bought an iPhone 5c with simlock to British operator and then restored it. Is it enough to have any nano-SIM or do I need the one from the carrier it is locked to in order to activate the phone? The only thing I need is to get to iOS. And if i need t
-
Desktop Manager show's an error!!
I am using Desktop manager version 5, when ever i connet my blackberry to my PC and open Desktop mananger it ask for an update for a APPLICATION LOADER! weill i press yes and then it downloads till 5.07mb and stops and says "please try again later" i