How to join multiple SQL statements?
I'm try to combine four of the following SQL statements as one, and I basically want to group by the new combined sql statement by suspension
Using: Oracle 10g
Here's my sql statements/what I've tried but doesn't seem to work:
select *
from
--NBA
select
decode (t.league_id, 1 , 'NBA') as League,
t.moniker as First,
t.Last_name as Last,
(t.To_Team_Name || ' ' || To_Team_Nickname) as Team,
count(*) Suspensions
from customer_data.cd_bk_trans t,
customer_data.cd_bk_roster r
where t.player_id = r.player_id
and t.trans_type_id in (12,13,14)
and r.status = 'Y'
and r.league_id = 01
group by t.league_id,t.last_name, t.moniker, t.to_team_name,t.to_team_nickname
order by Suspensions desc
union
--MLB
select
decode (t.league_id, 7 , 'MLB') as League,
t.moniker as First,
t.Last_name as Last,
(t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
count(*) Suspensions
from customer_data.cd_baseball_trans t,
customer_data.cd_baseball_roster r
where t.player_id = r.player_id
and t.comments like '%Susp%'
and r.status = 'Y'
and r.league_id = 07
group by t.league_id,t.last_name, t.moniker, t.from_team_name,t.from_team_nickname
order by Suspensions desc
union
--NHL
select
decode (r.team_id,18, 'NHL') as League,
t.fn as First,
t.ln as Last,
(t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
count(*) Suspensions
from customer_data.cd_nhl_trans t,
customer_data.cd_nhl_roster r
where t.player_id = r.player_id
and t.trans_type in (10,11,12)
and r.status = 'Y'
and r.league_id = 18
group by r.league_id, t.ln, t.fn, t.from_team_name,t.from_team_nickname
order by Suspensions desc
union
--NFL
select
decode (t.league_id, 8, 'NFL') as League,
t.moniker as First,
t.last_name as Last,
(t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
count(*) Suspensions
from customer_data.cd_football_trans t,
customer_data.cd_football_roster r
where t.player_id = r.player_id
and t.trans_type_id in (24,25)
and r.status = 'Y'
and r.league_id = 8
group by t.league_id, t.last_name, t.moniker, t.from_team_name,t.from_team_nickname
order by Suspensions desc
Order by Suspensions desc
Hi,
Remove the ORDER BY clause in all the queries expcept lastone. Then it will work.
You can have the ORDER BY clause in the last query of the inline view. Otherwise it will give the error.
Run the query given below
SELECT *
FROM (
--NBA
SELECT decode(t.league_id, 1, 'NBA') AS league,
t.moniker AS FIRST,
t.last_name AS LAST,
(t.to_team_name || ' ' || to_team_nickname) AS team,
COUNT(*) suspensions
FROM customer_data.cd_bk_trans t, customer_data.cd_bk_roster r
WHERE t.player_id = r.player_id
AND t.trans_type_id IN (12, 13, 14)
AND r.status = 'Y'
AND r.league_id = 01
GROUP BY t.league_id,
t.last_name,
t.moniker,
t.to_team_name,
t.to_team_nickname
UNION
--MLB
SELECT decode(t.league_id, 7, 'MLB') AS league,
t.moniker AS FIRST,
t.last_name AS LAST,
(t.from_team_name || ' ' || from_team_nickname) AS team,
COUNT(*) suspensions
FROM customer_data.cd_baseball_trans t,
customer_data.cd_baseball_roster r
WHERE t.player_id = r.player_id
AND t.comments LIKE '%Susp%'
AND r.status = 'Y'
AND r.league_id = 07
GROUP BY t.league_id,
t.last_name,
t.moniker,
t.from_team_name,
t.from_team_nickname
UNION
--NHL
SELECT decode(r.team_id, 18, 'NHL') AS league,
t.fn AS FIRST,
t.ln AS LAST,
(t.from_team_name || ' ' || from_team_nickname) AS team,
COUNT(*) suspensions
FROM customer_data.cd_nhl_trans t, customer_data.cd_nhl_roster r
WHERE t.player_id = r.player_id
AND t.trans_type IN (10, 11, 12)
AND r.status = 'Y'
AND r.league_id = 18
GROUP BY r.league_id,
t.ln,
t.fn,
t.from_team_name,
t.from_team_nickname
UNION
--NFL
SELECT decode(t.league_id, 8, 'NFL') AS league,
t.moniker AS FIRST,
t.last_name AS LAST,
(t.from_team_name || ' ' || from_team_nickname) AS team,
COUNT(*) suspensions
FROM customer_data.cd_football_trans t,
customer_data.cd_football_roster r
WHERE t.player_id = r.player_id
AND t.trans_type_id IN (24, 25)
AND r.status = 'Y'
AND r.league_id = 8
GROUP BY t.league_id,
t.last_name,
t.moniker,
t.from_team_name,
t.from_team_nickname
ORDER BY suspensions DESC)
ORDER BY suspensions DESC
Similar Messages
-
How to execute multiple sql statements
hi all
i am wondering if i can execute multiple sql statements in one shot with >> execute immediate command
for example:
i define the variable as X := sql statement
Y := sql statement
z := sql statement
can i do execute immediate (X,Y, Z);
if yes how ?? and if not any possible alternate
thanksStarting with Ganesh's code
DECLARE
l_statement VARCHAR2 (2000);
v_passwd VARCHAR2 (200);
v_username VARCHAR2 (200) := 'test';
v_pwd_key VARCHAR2 (200) := 'lwty23';
v_dblink_name VARCHAR2 (2000);
v_dblink_drop VARCHAR2 (2000);
v_dblink_create VARCHAR2 (2000);
v_dblink_check_connection VARCHAR2 (2000);
l_number NUMBER;
BEGIN
--<<c_instance>>
FOR c_instance IN (SELECT *
FROM v_oracle_instances
WHERE environment = 'Developement')
LOOP
SELECT encpwd_owner.display_db_encpwd (v_username,
c_instance.host_name,
c_instance.instance_name,
v_pwd_key)
INTO v_passwd
FROM DUAL;
v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name;
v_dblink_create :=
' CREATE DATABASE LINK '
|| v_dblink_name
|| ' CONNECT TO '
|| v_username
|| ' '
|| 'IDENTIFIED BY '
|| v_passwd
|| ' USING'
|| ' ''(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST= '
|| c_instance.host_name
|| ')(PORT='
|| c_instance.LISTENER_PORT
|| '))(CONNECT_DATA=(SID='
|| c_instance.instance_name
|| ')))''';
v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM'; --- Notice this change. I am simply selecting 1. That should be enough to test the database link.
v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF';
-- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;'
BEGIN
EXECUTE IMMEDIATE (v_dblink_create);
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created');
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name );
dbms_output.put_line( dbms_utility.format_error_backtrace() );
INSERT INTO error_table( column_list )
VALUES( <<list of values>> );
END;
EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number; --- Notice this.
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
BEGIN
EXECUTE IMMEDIATE (v_dblink_drop);
DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
EXCEPTION
WHEN others THEN
dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name );
dbms_output.put_line( dbms_utility.format_error_backtrace() );
INSERT INTO error_table( column_list )
VALUES( <<list of values>> );
END;
END LOOP;
END;But I agree with the point that others have brought up that it really doesn't make sense to create and drop a database link like this.
Justin -
How to execute multiple SQL statements thru frontend?
With SQL Server database, you can execute multiple SQL statements.
Ex.
SQLCommand cmd = new SQLCommand();
cmd.CommandText = "SELECT * FROM EMP; SELECT * FROM DEPT";
cmd.ExecuteXXX();
Note that for SQL Server, ";" (semocolon) is used as a separator.
What separator is required for Oracle ? Or rather, can I execute multiple SQL statements against Oracle database (10g) ?
(Why I want to do it is a totally diff. subject !)
Thanks,
Ami.Hello,
You could use an anonymous PL/SQL block to batch multiple statements.
If you want to use SELECT statements, you would open a REF CURSOR for each SELECT and return the REF CURSOR to your application. INSERT, UPDATE, and DELETE statements can just be passed as is.
A simple REF CURSOR example might look like:
begin
open :v_refcursor1 for select * from emp;
open :v_refcursor2 for select * from dept;
end;Where v_refcursor1 and v_refcursor2 are parameters defined as a REF CURSOR type.
Hope that helps a bit...
- Mark -
How to execute multiple sql statements in parallel ?
Hi There,
I have 10 stored procedures, each one will take approximately 5 seconds to run individually.
Now I need to combine the results of these 10 stored procedures into single result set.
So I have created one more stored procedure "proc_AllSPs" to get the single result set.
The procedure "proc_AllSPs" is taking one minute to run because all the procedures inside the "proc_AllSPs" are running
one after the other and taking 5 seconds each.
If there is any other way that all the procedures run parallelly, then the procedure "proc_AllSPs" can run in 5 seconds time.
Sorry if I am not being elaborated.
PLease get back to me if any piece of information is needed.
Any kind of help is truly thankful.
Thanks,
SequelBugCould you tell me how to execute two stored procedures or two sql statements in parallel
For eg:
First procedure name is proc_sp1 which takes 1 minute to run
Second procedure name is proc_sp2 which takes 1 minute to run
I want to accomplish the below query in 1 minute by executing statement1 and statement2 parallelly.
go
select * from openrowswt('sqloledb','server','exec proc_sp1') --statement1
union
select * from openrowset('sqloledb','server','exec proc_sp2') --statement2
go
OR
go
Select * into #Temp1 from openrowswt('sqloledb','server','exec proc_sp1') --statement1
select * into #Temp2 from openrowset('sqloledb','server','exec proc_sp2') --statement2
Select * from #Temp1
UNION ALL
Select * from #Temp2
go
Thanks,
SequelBug -
How to execute multiple sql statements in oracle?
I want to execute multiple statements in a single transaction in oracle. Following are my queries:
Create table temp_table as Select * from table;
SELECT * FROM temp_table d;
drop table temp_table ;
I am using sql comment text in asp.net
I am using executenonquery command in asp.net.
Thanks,
DivyaSigCle ,
Here's an example that executes 3 statements;
begin insert into foo values(1); insert into foo values(2); insert into foo values(3); end;
923354,
The block doesn't compile because temp_table doesn't exist at the point you're trying to compile the anonymous block. I'd recommend re-reading the doc link and forum link provided to get a better understanding of how temp tables work, as it's simply different with Oracle. You don't create Oracle temporary tables on the fly; you create them ahead of time and then just use them. The data itself is already specific to a particular session; you don't create and drop the table each time.
Also, you can't just "select * from table" in plsql. The results have to GO SOMEWHERE. Usually you'd either open a cursor and process it in the block, or send out a ref cursor if you want to send the data to a client side app. The ref cursor data wouldn't actually be fetched until the block completes though, so you'd need to use ON COMMIT PRESERVE ROWS, which would also mean you'd need to clean up the data yourself (delete the data from the table when you're done with it).
Corrections/comments welcome.
Greg -
How to execute multiple sql statement?
In an single transaction I want to execute two update statements. I don't know how to break those statements and send to oracle from Asp.Net to execute.
I tried go and ; .
Below is myQuery string*
update abc set One = 10 where Two = 3 ; update xyz set Three = 10 where Four = 3 ;
Additional info
I am using sql comment text in asp.net
I am using executenonquery command in asp.net.Hi,
If you want to execute multiple statements in a single transaction, you could either:
a) create a local transaction (via an OracleTransaction object), then call executenonquery multiple times within that transaction, or
b) pass them all in an anonymous block for a single round trip.. ie, begin update abc set One = 10 where Two = 3 ; update xyz set Three = 10 where Four = 3 ;end;
The database doesn't permit multiple statements passed at once (other than in a plsql block).
Hope it helps, corrections/comments welcome
Greg
PS, questions such as this would be better posted in the ODP.NET forum; this forum is for issues regarding ODT.NET (a VS plugin)
ODP.NET -
Multiple SQL statements in Init SQL in WLS 8.1
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do I seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxMahendra wrote:
Thanks Joe.
Following worked for Oracle 8.1.7Good news.
but did not for 8.0.6
SQL BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''MM/DD/YYYY''';
EXECUTE IMMEDIATE 'SET ROLE xxx identified xxx'; end;
Do you know 8.0.6 syntax ?You might try asking oracle, but note that no one is supporting that old version
of Oracle any longer...
Joe
>
Mahendra
Joe Weinstein <[email protected]> wrote:
Hi.
I found the syntax, I think. Try this:
BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = 'MM/DD/YYYY'';
EXECUTE IMMEDIATE 'SET ROLE <<role name>> identified
by <<pwd>>';END;
Joe
Mahendra wrote:
Still getting following exception.
<Feb 19, 2004 1:47:58 PM EST>
<Warning>
<JDBC> <BEA-001164>
<Unable to initialize connection in pool "XXXX".
Initialization
SQL = "BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole xxxx_role
identified by
xxxx; END;".
Received exception: "java.sql.SQLException: ORA-06550: line 1,column7:
PLS-00103: Encountered the symbol "ALTER" when expecting one of thefollowing:
begin declare exit for goto if loop mod null pragma raise
return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql commit <a single-quoted SQL string>
The symbol "update was inserted before "ALTER" to continue.
ORA-06550: line 1, column 61:
PLS-00103: Encountered the symbol "ROLE" when expecting one of thefollowing:
transaction
".>
<Feb 19, 2004 1:47:59 PM EST> <Notice> <WebLogicServer> <BEA-000355><Thread "Li
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
Thanks for reply, but that did not worked.
Get following exception
Unable to initialize connection pool "POOL_NAME".
Initialization SQL = "Select count(*) from ""SQL BEGIN alter sessionset nls_date_format
= 'MM/DD/YYYY'; set role xxx_role identified by xxxx; END;"". Receivedexception:
"java.sql.SQLException: ORA-00972: identifier is too long
Since we have not given SQL before that statement, BEA is treating
statment "SQL Begin ....." as a table name.
Then I tried by putting SQL out side quotes, like SQL "Begin .....end;" but the
same error.
Is there any way around it ?
MahendraHi. The full string you should enter into the console when you define
the
initSQL parameter is:
SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; set role
xxx_role identified by xxxx; END;
Let me know...
Joe
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do
I
seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxThis will always be DBMS-specific. If this is for oracle, you can
try:
"SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole
xxx_role identified by xxxx; END;"
Joe -
How do I use SQL statements to perform calculations with form fields????
Please help!!! I don't know how to use a SQL statement within my APEX form......
My form is below. The user will enter the values in the form. Click on Submit. Then we need to run a SQL select statement with those values.
Our form looks like this:
Start_Date ____________
Per_Period ____________
Period ____________
[Submit Button]
The user will enter these 3 values in the form.
This is an example of an user providing the values:
Start_Date 03/14/08_______
Per_Period $200.00________
Period 4____________
[Submit Button]
Then they will click the Submit Button.
The SQL statement (BELOW) returns output based on the users selections:
START_DATE PER_PERIOD PERIOD
14-MAR-2008 00:00 200 Week 1 of 4
21-MAR-2008 00:00 200 Week 2 of 4
28-MAR-2008 00:00 200 Week 3 of 4
04-APR-2008 00:00 200 Week 4 of 4
Total 800
This is the full text of the SQL that makes the output above:
with criteria as (select to_date('03/14/08', 'mm/dd/rr') as start_date,
4 as periods,
'Week' as period,
200 per_period from dual),
periods as (select 'Week' period, 7 days, 0 months from dual
union all select 'BiWeek', 14, 0 from dual
union all select 'Month', 0, 1 from dual
union all select 'ByMonth', 0, 2 from dual
union all select 'Quarter', 0, 3 from dual
union all select 'Year', 0 , 12 from dual
t1 as (
select add_months(start_date,months*(level-1))+days*(level-1) start_date,
per_period,
c.period||' '||level||' of '||c.periods period
from criteria c join periods p on c.period = p.period
connect by level <= periods)
select case grouping(start_date)
when 1 then 'Total'
else to_char(start_date)
end start_date,
sum(per_period) per_period,
period
from t1
group by rollup ((start_date, period))
THANKS VERY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!You're just doing a parameterized report, where the input fields are your parameters.
Check out the Advanced Tutorial titled Parameterized Report here:
http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10497/rprt_query.htm#BGBEEBJA
Good luck,
Stew -
Hey all
How do I create multiple sql statements? I know how to add a single line, but how do I efficiently insert multiple lines? Should I create a new string called "qry2" and then just add that to my executeUpdate statement?
//dbtest.jsp
String qry = "INSERT INTO item VALUES ('" postedItem "', '" stamp "');";
addStmt.executeUpdate(qry);You can have a separate variable, or you can just reuse qry.
As a side note, I strongly recommend you use PreparedStatement rather than Statement, and use its "?" parameters for the values you're going to insert: qry = "INSERT INTO item VALUES(?, ?)";
qry.setString(1, postedItem);
qry.setTimestamp(2, stamp); // or setString, or whatever type is appropriate for stamp -
How to send multiple customer statements by email using RFKORD11 program.
Hi All,
How to send multiple customer statements by email using RFKORD11 program. Is it possible?
As of now we copied the stanadard program and sending the customer statements by email, one by one.
if i execute the z program it will show the customer statement and send mail option.
if i click send mail it will send that customer statement to the corresponding customer.
then again i need to click back, it will show next customer statement and click on send mail.
Pl guide me, if any one worked on this program.
thanks in advance.
Regards,
MaheshTry execute the program in the background to see if that helps.
-
How to send multiple customer statements by email using RFKORD11
Hi All,
How to send multiple customer statements by email using RFKORD11 program.
As of now we copied the stanadard program and sending the customer statements by email, one by one.
if i execute the z program it will show the customer statement and send mail option.
if i click send mail it will send that customer statement to the corresponding customer.
then again i need to click back, it will show next customer statement and click on send mail.
Pl guide me, if any one worked on this program.
Regards,
MaheshHi .
You first need to copy that program to Z and make the changes in it. Can you convert sapscript to smartform?
then you can write a logic to send mail in the loop.
to send the pdf file
https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/mailsendthroughoutputcontrols
Regards,
Madhuri
Edited by: madhuri sonawane on Jun 10, 2009 4:20 PM -
How to put the SQL-statement returned value into the field (as a default)
Hi,
I am using Developer/2000 (Forms Designer) under windows 98.
Please tell me how to put the SQL-statement value (as a default value) into the field before enter-query mode. Noted that I have tried the following ways but still some problems:-
1) Place the SQL-statement into PRE_QUERY trigger in the form/block level.
There is a message box which ask 'Do you want to save the changes?'.
2) Place the SQL-statement before execute enter_query. There is still a
message box which ask 'Do you want to save the changes?'.
Any hints? Thanks. Urgent.solved it!
1) Suppress DEFAULT save message
if form_failure then
raise form_trigger_failure;
end if;
2) Place the default value before enter-query.
Ref: Title='Default value in query field in ENTER_QUERY mode' in designer forum by CVZ
form level trigger
============
WHEN-NEW-ITEM-INSTANCE
=======================
if :system.mode = 'ENTER-QUERY' then
:block.item := 'default waarde';
end if;
3) Suppress the changes whenever leaving the default field.
if :block.item is null then
-- assign statement
end if; -
How to write the sql statement of my finder function in cmp?
hi,
I create a cmp ejb from table INFOCOLUMN,and I create a my finder function ,which sql statement is :
select * from INFOCOLUMN WHERE employee_id=id
employee_id is a column of the table,and id is the finder function parameter.
The error is : invalid column name
So,how to write the sql statement.
Thanks .Mole-
Bind variables are of the form $1, $2, etc., so your query stmt should look like:
select * from INFOCOLUMN WHERE employee_id=$1
-Jon -
How to open multiple sql files in only one ssms instance
how to open multiple sql files in only one ssms instance, I can't get anything to work that I find online..I hope you can help us.
I tried opening two files but selecting and hitting enter. it opens one SSMS and two tabs.
Balmukund Lakhani
Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
This posting is provided "AS IS" with no warranties, and confers no rights.
My Blog |
Team Blog | @Twitter
| Facebook
Author: SQL Server 2012 AlwaysOn -
Paperback, Kindle -
XML Publisher - can we specify multiple SQL statements in the report?
Hi there,
can we specify multiple SQL statements in the report with XML Publisher?
Regards,
LiviuCould we eventually generate with the Wizards available in XML Publisher desktop 5.6.2 an xml file with a structure like the one given below? The reason is to facilitate creation of the two rowsets. Thanks, Liviu.
<?xml version="1.0" encoding="UTF-8"?>
<DATA>
<ROWSET2>
<ROW2>
<FIELD1>Query1</FIELD1>
<FIELD2>field2</FIELD2>
<FIELD3>field3</FIELD3>
</ROW2>
</ROWSET2>
<ROWSET>
<ROW>
<FIELD1>Query2</FIELD1>
<FIELD2>field2</FIELD2>
<FIELD3>field3</FIELD3>
</ROW>
</ROWSET>
</DATA>
Maybe you are looking for
-
Jamming with the Arpeggiator not right
So I know how to set up the arp in logic no problem, also delay lines and all that good stuff, the problem is this. On other Arps I can jam by playing arped notes very quickly then holding down the note when I want the arp to work. In logic this is n
-
Cannot open video on some news sites
Firefox has stopped opening news videos from fox news
-
Two Fabric redundancy and storage flapping
Hello! I have a fairly new Nexus 5548 implementation, using the Nexus for stricly storage. I have two 5548s for two different Fabrics, for redundancy. They are two seperate fabrics, and the Nexus are not stacked so they are managed individually. When
-
I used my ipod this morning before i went to class. it worked fine. when i got to class i turned it off. after class, i went to turn it on and it just stayed blank. i plugged to my l-top and it wont turn on[it usually does] i unplugged the usb cable
-
IPhoto won't launch anymore.
Hi folks, I recently had to create a new admin account for my dual quad-core G5 (OS 10.4.11) and then do an archive-and-install from the original system disks, then recreate my original admin account. All previous settings are saved in a "Previous Sy