Solved

How to reference the primary table in a nested select in an Update statement

Posted on 2008-10-24
3
301 Views
Last Modified: 2013-12-07
I'm getting the following error when trying to run the attached Update statement.   It occurs on the line in the nested selects that reference the DT.taskorder field.  

Can anyone help?

PL/SQL:  ORA-00904: "DT"."TaskOrder": invalid identifier.

UPDATE go.Tasks DT
SET	StartDate = 
	(Select startdate from 
		(select startdate 
		from go.Tasks X 
		where X.ePHPID 	= p_ePHPID 
		and X.Method 	= p_Method 
		and X.TaskOrder	= DT.taskorder 
		and X.Subtask 	= 'N' 
		order by X.taskorder)
	Where RowNum = 1),
	EndDate =
	(Select endDate from 
	         (Select endDate 
                                  from go.Tasks W
		where W.ePHPID 	= p_ePHPID 
		and W.method 	= p_Method 
		and W.TaskOrder	= DT.taskorder 
		and W.Subtask	= 'N'  
		order by W.taskorder),
	Where rowNum = 1)
where ePHPID = p_ePHPID 
and Method = p_Method 
and Subtask = 'Y';

Open in new window

0
Comment
Question by:sgrzesik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:jfmador
ID: 22798449
Hello sorry I don't know much oracle but I you are defining twice your query, Under SQL Server i would give a try to something like this


update Tasks
SET Tasks.StartDate = t.StartDate, Tasks.EndDate = t.EndDate
from Tasks inner join
(
	Select TasksOrder, min(startdate) as startdate, min(endDate) as enddate  
	FROM go.Tasks x
	inner join go.Tasks dt on x.TaskOrder = dt.TaskOrder and x.EPHPID = dt.EPHPID AND x.Method = dt.Method
	where X.ePHPID 	= p_ePHPID 
	and X.Method 	= p_Method 
	and X.Subtask 	= 'N' 
	AND dt.subtask  = 'Y'
	GROUP BY TasksOrder
) t on Tasks.TasksOrder = t.TasksOrder

Open in new window

0
 
LVL 9

Accepted Solution

by:
MarkusId earned 500 total points
ID: 22798604
Hi!

As far as I know it was not possible (at least until version 9) to reference an external column in a nested select. So you might this give a try:
UPDATE go.Tasks DT
SET     StartDate = 
        (Select startdate from 
                (select startdate, X.TaskOrder
                from go.Tasks X 
                where X.ePHPID  = p_ePHPID 
                and X.Method    = p_Method 
                and X.Subtask   = 'N' 
                order by X.taskorder) x
        Where x.taskOrder = dt.taskorder
        and   RowNum = 1),
        EndDate =
        (Select endDate from 
                 (Select endDate, x.TaskOrder
                                  from go.Tasks W
                where W.ePHPID  = p_ePHPID 
                and W.method    = p_Method 
                and W.Subtask   = 'N'  
                order by W.taskorder) w
        Where w.taskorder = dt.taskorder
          and rowNum = 1)
where ePHPID = p_ePHPID 
and Method = p_Method 
and Subtask = 'Y';

Open in new window

0
 

Author Comment

by:sgrzesik
ID: 22799145
That works, thanks!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Require data to appear on a single line 2 81
Row_number in SQL 6 45
oracle query 3 26
looking for guidance on Oracle Sql Formatting standards 9 32
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question