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
Regards
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,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
Similar Messages
-
Oracle 8i - PL/SQL sub query not working in PROC, but works ins SQL
I have read about certain things not working in 8i and I think this is one of them, but I was wondering if anyone had a work around. In the place of the SELECT SYSDATE FROM DUAL, I have a table look up, where I am going to look up the OCN of the corresponding VENDOR_ID ( a column in the original query ). I am doing it in a decode statement because if the first condition in the decode statement is met, that's it. But if not, it needs to look up the OCN number in this other table. Simple enough, conceptually. I thought of a view but that necessitates a SELECT statement, too. Anyway, here is the code with the appropriate text bolded:
CREATE OR REPLACE PROCEDURE tstINS_RATE_ROUTE_RECORDS_PROC (GET_CUR_PERIOD IN DATE) IS
CUR_PERIOD DATE;
BEGIN
CUR_PERIOD := GET_CUR_PERIOD;
Insert into RATE_ROUTE (
CVBI_KEY
, VENDOR_ID
, OCN
, ST_CD
, PERIOD
, MDFY_DT )
Select
C.CVBI_KEY
, C.VENDOR_ID
<b>, decode( c.send_lca, 'YES', 'XXX', (SELECT SYSDATE FROM DUAL) )</b>
, decode( c.send_lca, 'YES', 'XX', SUBSTR(C.ZLOC,5,2) )
, CUR_PERIOD
, TO_CHAR(SYSDATE)
FROM
rpt_ds1_cnt_cat c
, cogs_resource cr
, cogs_t1activity ct1
, rpt_ds1_aloc_zloc_reverse_vw az
where (C.CVBI_KEY = CR.CVBI_KEY (+)
and CR.PERIOD = CUR_PERIOD)
AND (C.CVBI_KEY = CT1.CVBI_KEY (+)
and CT1.PERIOD = CUR_PERIOD)
and (az.master_route_name=c.aloc||'-'||c.zloc OR az.reversed=c.aloc||'-'||c.zloc)
END; -- INS_RATE_ROUTE_RECORDS_PROChave read about certain things not working in 8i and I think this is one of them,Yes as I said scalar sub-queries were also not recognized within PL/SQL in 8i.
Re: PLS-00103: Encountered the symbol "SELECT" when expecting one of the fo
I was wondering if anyone had a work around.Write a function that returns the value. You may incur a performance penalty from a context switch to PL/SQL, but it may be balanced by the decode optimization you are attempting. -
Dear Sir/Madam
I'm a student who is interested in Oracle Database and
I have some problems with JOIN and Sub-query.
I hope so many of you could help me.
if i use JOIN without sub-query, may it be faster or not?
SELECT field1, field2 FROM tableA INNER JOIN tableB
if i use JOIN with sub-query, may it be faster or not?
SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
Thanks in advance!Hi,
fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
Dear Sir/Madam
I'm a student who is interested in Oracle Database and
I have some problems with JOIN and Sub-query.
I hope so many of you could help me.
if i use JOIN without sub-query, may it be faster or not?
SELECT field1, field2 FROM tableA INNER JOIN tableB
if i use JOIN with sub-query, may it be faster or not?
SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
Thanks in advance!
As the others have said, the execution plan will give you a better idea about which is faster.
If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible. For example, include field3 in both queries, or ignore field3 in both queries.
In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess. I can't see your execution plans.
In general, simpler code is faster, and better in other ways, too. In this case
tableB
is simpler than
(SELECT field1, field2 FROM tableB)
Why do you want a sub-query in this example? -
Oracle date parameter query not working?
http://stackoverflow.com/questions/14539489/oracle-date-parameter-query-not-working
Trying to run the below query, but always fails even though the parameter values matches. I'm thinking there is a precision issue for :xRowVersion_prev parameter. I want too keep as much precision as possible.
Delete
from CONCURRENCYTESTITEMS
where ITEMID = :xItemId
and ROWVERSION = :xRowVersion_prev
The Oracle Rowversion is a TimestampLTZ and so is the oracle parameter type.
The same code & query works in Sql Server, but not Oracle.
Public Function CreateConnection() As IDbConnection
Dim sl As New SettingsLoader
Dim cs As String = sl.ObtainConnectionString
Dim cn As OracleConnection = New OracleConnection(cs)
cn.Open()
Return cn
End Function
Public Function CreateCommand(connection As IDbConnection) As IDbCommand
Dim cmd As OracleCommand = DirectCast(connection.CreateCommand, OracleCommand)
cmd.BindByName = True
Return cmd
End Function
<TestMethod()>
<TestCategory("Oracle")> _
Public Sub Test_POC_Delete()
Dim connection As IDbConnection = CreateConnection()
Dim rowver As DateTime = DateTime.Now
Dim id As Decimal
Using cmd As IDbCommand = CreateCommand(connection)
cmd.CommandText = "insert into CONCURRENCYTESTITEMS values(SEQ_CONCURRENCYTESTITEMS.nextval,'bla bla bla',:xRowVersion) returning ITEMID into :myOutputParameter"
Dim p As OracleParameter = New OracleParameter
p.Direction = ParameterDirection.ReturnValue
p.DbType = DbType.Decimal
p.ParameterName = "myOutputParameter"
cmd.Parameters.Add(p)
Dim v As OracleParameter = New OracleParameter
v.Direction = ParameterDirection.Input
v.OracleDbType = OracleDbType.TimeStampLTZ
v.ParameterName = "xRowVersion"
v.Value = rowver
cmd.Parameters.Add(v)
cmd.ExecuteNonQuery()
id = CType(p.Value, Decimal)
End Using
Using cmd As IDbCommand = m_DBTypesFactory.CreateCommand(connection)
cmd.CommandText = " Delete from CONCURRENCYTESTITEMS where ITEMID = :xItemId and ROWVERSION = :xRowVersion_prev"
Dim p As OracleParameter = New OracleParameter
p.Direction = ParameterDirection.Input
p.DbType = DbType.Decimal
p.ParameterName = "xItemId"
p.Value = id
cmd.Parameters.Add(p)
Dim v As OracleParameter = New OracleParameter
v.Direction = ParameterDirection.Input
v.OracleDbType = OracleDbType.TimeStampLTZ
v.ParameterName = "xRowVersion_prev"
v.Value = rowver
v.Precision = 6 '????
cmd.Parameters.Add(v)
Dim cnt As Integer = cmd.ExecuteNonQuery()
If cnt = 0 Then Assert.Fail() 'should delete
End Using
connection.Close()
End Sub
Schema:
-- ****** Object: Table SYSTEM.CONCURRENCYTESTITEMS Script Date: 1/26/2013 11:56:50 AM ******
CREATE TABLE "CONCURRENCYTESTITEMS" (
"ITEMID" NUMBER(19,0) NOT NULL,
"NOTES" NCHAR(200) NOT NULL,
"ROWVERSION" TIMESTAMP(6) WITH LOCAL TIME ZONE NOT NULL)
STORAGE (
NEXT 1048576 )
Sequence:
-- ****** Object: Sequence SYSTEM.SEQ_CONCURRENCYTESTITEMS Script Date: 1/26/2013 12:12:48 PM ******
CREATE SEQUENCE "SEQ_CONCURRENCYTESTITEMS"
START WITH 1
CACHE 20
MAXVALUE 9999999999999999999999999999still not comming...
i have one table each entry is having only one fromdata and one todate only
i am running below in sql it is showing two rows. ok.
select t1.U_frmdate,t1.U_todate ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf
from [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
on t0.DocEntry = t1.DocEntry
inner join ohem t2
on t2.empID = t0.U_empid where t0.U_empid between '830' and '850' and t1.U_frmdate ='20160801' and t1.u_todate='20160830'
in commond promt
select t1.U_frmdate,t1.U_todate ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf
from [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
on t0.DocEntry = t1.DocEntry
inner join ohem t2
on t2.empID = t0.U_empid where t0.U_empid between {?FromEmid} and {?ToEmid} and t1.U_frmdate ={?FDate} and t1.u_todate={?TDate}
still not showing any results.. -
How to make outer join in Sub Query?
Hi!
I'm facing one problem. Can anyone tell me - how to make outer join in sub query?
I'm pasting one sample code -
select e.empno, e.ename,e.job,e.sal,d.deptno,d.dname
from d_emp e, d_dept d
where e.deptno(+) = (
case
when d_dept.deptno = 10
then
select deptno
from d_dept
where dname = 'SALES'
else
d_dept.deptno
end
SQL>
ERROR at line 15:
ORA-01799: a column may not be outer-joined to a subqueryHow to resolve this issue?
Regards.And any luck with this?
SQL> with emp as
2 (select 100 empno, 'Abcd' ename, 1000 sal, 10 deptno from dual
3 union all
4 select 101 empno, 'RRR' ename, 2000 sal, 20 deptno from dual
5 union all
6 select 102 empno, 'KKK' ename, 3000 sal, 30 deptno from dual
7 union all
8 select 103 empno, 'PPP' ename, 4000 sal, 10 deptno from dual
9 )
10 ,dept as
11 (select 10 deptno, 'FINANCE' dname from dual
12 union all
13 select 20 deptno, 'SALES' dname from dual
14 union all
15 select 30 deptno, 'IT' dname from dual
16 union all
17 select 40 deptno, 'HR' dname from dual
18 )
19 select e.empno, e.ename, e.sal, d.deptno, d.dname
20 from emp e,
21 (select decode(a.deptno, 10, b.deptno, a.deptno) deptno, decode(a.deptno, 10, b.dname, a.dname) dname
22 from dept a, (select deptno, dname
23 from dept
24 where dname = 'SALES'
25 ) b
26 ) d
27 where e.deptno(+) = d.deptno
28 /
EMPNO ENAM SAL DEPTNO DNAME
101 RRR 2000 20 SALES
101 RRR 2000 20 SALES
102 KKK 3000 30 IT
40 HR
SQL> Cheers
Sarma. -
I have written the below query, our requirement is, Some employees have "Transport Allowance" but not "Project Allowance". For this, I tried to use OUTER JOIN with this query. But this query takes long time and failed. The following query works fine if the employee has both "Transport Allowance" and "Project Allowance" (without outer join) Now, I also need to retrieve the employees who have "Transport Allowance" but not "Project Allowance". How can I retrieve it?
SELECT DISTINCT papf.employee_number
, peev.screen_entry_value Transport_Allowance
,peev1.screen_entry_value Project_Allowance
FROM apps.per_all_people_f papf
,apps.per_all_assignments_f paaf
,apps.pay_element_types_x petf
,apps.pay_element_types_x petf1
,apps.pay_element_types_x petf2
,apps.pay_element_entries_f peef
,apps.pay_element_entries_f peef1
,apps.pay_element_entries_f peef2
,apps.pay_element_entry_values_x peev
,apps.pay_element_entry_values_x peev1
,apps.pay_element_entry_values_x peev2
,apps.pay_input_values_x pivf
,apps.pay_input_values_x pivf1
,apps.pay_input_values_x pivf2
WHERE
papf.person_id = paaf.person_id
AND paaf.assignment_id = peef.assignment_id
AND paaf.assignment_id = peef1.assignment_id
AND paaf.business_group_id = papf.business_group_id
--Transport Allowance
AND peef.element_entry_id = peev.element_entry_id
AND petf.element_Name = 'Transport Allowance'
AND pivf.element_type_id =petf.element_type_id
AND pivf.name = 'Allowance'
AND peev.input_value_id= pivf.input_value_id
--Project Allowance
AND peef1.element_entry_id = peev1.element_entry_id
AND petf1.element_Name = "Project Allowance'
AND pivf1.element_type_id = petf1.element_type_id
AND pivf1.name = 'Allowance'
AND peev1.input_value_id = pivf1.input_value_id
AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
ORDER BY papf.employee_number
Thanks in advance.I am using sames tables with alias to retrieve the columns values from the same table.
Here is my query.
SELECT DISTINCT papf.employee_number
, peev.screen_entry_value Transport_Allowance
,peev1.screen_entry_value Project_Allowance
FROM apps.per_all_people_f papf
,apps.per_all_assignments_f paaf
,apps.pay_element_types_x petf
,apps.pay_element_types_x petf1
,apps.pay_element_entries_f peef
,apps.pay_element_entries_f peef1
,apps.pay_element_entry_values_x peev
,apps.pay_element_entry_values_x peev1
,apps.pay_input_values_x pivf
,apps.pay_input_values_x pivf1
WHERE
papf.person_id = paaf.person_id
AND paaf.assignment_id = peef.assignment_id
AND paaf.assignment_id = peef1.assignment_id
AND paaf.business_group_id = papf.business_group_id
--Transport Allowance
AND peef.element_entry_id = peev.element_entry_id
AND petf.element_Name = 'Transport Allowance'
AND pivf.element_type_id =petf.element_type_id
AND pivf.name = 'Allowance'
AND peev.input_value_id= pivf.input_value_id
--Project Allowance
AND peef1.element_entry_id = peev1.element_entry_id
AND petf1.element_Name = "Project Allowance'
AND pivf1.element_type_id = petf1.element_type_id
AND pivf1.name = 'Allowance'
AND peev1.input_value_id = pivf1.input_value_id
AND (SYSDATE BETWEEN peev.effective_start_date AND peev.effective_end_date)
AND (SYSDATE BETWEEN peev1.effective_start_date AND peev1.effective_end_date)
AND (SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date)
ORDER BY papf.employee_number
Thanks in advance. -
iPod nano 6th generation, syncing with audiobooks does not work now, had been working. Sync test says: No iPod touch, iPhone, or iPad found. Connectivity test OK, no physical problems, iTunes shows the iPod. Any clues what to do?
Hmm.. Thank you for the response.
Have you tried using the iPod with another user account or computer, to help narrow down whether the problem lies with the computer, account, or the iPod itself?
Maybe try reformatting it, using the tools provided by Windows. Instructions on how to reformat your iPod can be found in this article.
http://www.methodshop.com/gadgets/ipodsupport/erase/index.shtml
B-rock -
Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work. Please help. I am getting lots of spelling errors as the MacBook laptop screen is too small. Thank you so much! .
Contentmom6 wrote:
Brand new Mac user help please! How do you connect a 17" monitor to the MacBook? I have the monitor plugged into the Mac, but the F8 that I am used to with PC does not work.
Normally, you just connect the monitor to the MacBook using a VGA adaptor that you can buy from an Apple Store. Now try System Preferences > Displays > Detect Displays. You should now be able to select a display mode for the monitor. If it still doesn't work, then I'd check that everything is properly connected. I've had problems with colours disappearing due to a faulty connection in the VGA adaptor.
Bob -
FIND with MATCH OFFSET not working
Hi,
I have a statement:
FIND '/' IN <ls_data_package>-/bic/zbib_sysn MATCH OFFSET off2.
this works in all the case except for when <ls_data_package>-/bic/zbib_sysn = SSULTANA-VMC/.
(i.e. when /bic/zbib_sysn = USERID-VMC/, here SSULTANA is the user ID)
*In this case off2 = .
Value of sy-subrc is 0 after this statement is executed
Can some one please point out what I am doing wrong.
Thank you,
CD
Edited by: CSD . on Sep 26, 2008 9:53 PM>FIND with MATCH OFFSET not working
Most unlikely. More likely is that it isn't doing what you think it should be doing. Or you're using it incorrectly!
I can't really follow what your problem is. I assume you mean that you are getting off2 with value 0, when /bic/zbib_sysn contains USERID-VMC/
Can you be a little clearer in what the issue is?
DATA: off2 TYPE i.
FIND '/' IN 'this string /' MATCH OFFSET off2.
WRITE: / sy-subrc, off2.
This little program returns 0 and 12
matt -
Problem Summary
Cancel Query not working on 11.5.10
Problem Description
While finding orders, window pops up the cancel query but when user tries to click the cancel button, query does not cancel.jemar98 wrote:
Problem Summary
Cancel Query not working on 11.5.10
Problem Description
While finding orders, window pops up the cancel query but when user tries to click the cancel button, query does not cancel.Please post the details of the application release, database version and OS.
Was this working before? If yes, any changes been done recently?
Please review (Canceling Long Running Queries in Oracle Applications 11i [ID 138159.1]) and make sure you complete all the steps.
Thanks,
Hussein -
I am having trouble with my speakers not working while online particular on facebook. My audio works when playing audio files.
Hi,
Did it happen all the time or sometime?
Please check online browser status:
Click Volume icon in the taskbar, click Mixer link button as below:
If it's fine, follow this guide to run troubleshooter to detect and fix the issue:
Tips for fixing common sound problems
http://windows.microsoft.com/en-in/windows/tips-fixing-common-sound-problems#tips-fixing-common-sound-problems=windows-7
Meanwhile, this similar thread also could be referred:
https://social.technet.microsoft.com/forums/ie/en-US/a4a1cfe5-93a5-4c0b-9bf6-f7db0304f2ba/no-sound-on-youtube-or-any-other-webpage
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected] -
Serial number provided with download does not work, now what?
serial number provided with download does not work, now what?
Chrish29593217 you are welcome to contact our directly at Contact Customer Care. What Adobe software title are you facing difficulties with?
-
I've a report with sub-query. I ran it separately to test it and it was fine. When I ran the whole report, I always get error with it.
Could someome put some light on it?
Thanks,
TedHi,
What is the error you are getting
Regards
MuRam -
TS3297 i bot a 3g iphone 2nd hand and it is trobleing a lot with os and not working plese help me
i bot a 3g iphone 2nd hand and it is trobleing a lot with os and not working plese help me
The following guide gives information on how to sync ringtones from your computer to the phone. The reference section at the bottom of the quide also gives instructions on how to convert a song to a ringtone. https://discussions.apple.com/docs/DOC-3792
-
Revision: 4323
Author: [email protected]
Date: 2008-12-15 19:23:10 -0800 (Mon, 15 Dec 2008)
Log Message:
Bug: LCDS-544 - Scenario where two components have seperate channel sets with overlapping channels not working.
QA: Yes
Doc: No
Checkintests Pass: Yes
Details:
* Hunting to a new channel within a channelset never triggered a disconnect from the previous channel(s). This isn't a problem in general, but does becomes a problem when an app defines two distinct channelsets containing at least one shared channel at the head of the list. In this case, the first channelset hunts past it and connects on a later channel. But when the second channelset hunts through (triggering a connect fault when it hits that initial shared channel that can't connect), the fault is processed by the first channelset as well (incorrectly).
Ticket Links:
http://bugs.adobe.com/jira/browse/LCDS-544
Modified Paths:
flex/sdk/trunk/frameworks/projects/rpc/src/mx/messaging/ChannelSet.asRunning the script by python2 solves it for me:
su - mythtv -c "nice -n 19 python2 /usr/bin/tv_grab_nl_py --output ~/listings.xml"
Best regards,
Cedric
Maybe you are looking for
-
[Solved] SDDM does not unlock gnome-keyring
Hi everyone! I did some searching but didn't find the answer to my issue yet. I'm using SDDM to log in to i3. The issue is that my keyring doesn't get unlocked after login and it asks for the password on first access (owncloud client). Now I want to
-
Can't install Quick Time (VBScript error)
I recently got a new computer and I have a kodak digital camera that also records small videos. I installed the kodak software and I tried to play a video it told me I needed to install Quick Time, so I tried to download it and when it was finished d
-
I followed your instruction and went into mailboxes and then clicked on rebuild, but nothing happened. What do I do?? Raya
-
I downloaded the new software ios5 the other day. Woke up this morning and all my calendar events are gone! How do I get everything back??
-
Canon HF10 and Premiere Elements 8
Hello! I have a Canon Vixia HF 10 that I am trying to use with the Adobe 8 Premiere Elements trial. When I click the "AVCHD or other hard disk/memory camcorder" option in the Get Media tab, my camera is not recognized as an import source. It is recog