Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my update query I want to fetch data in output clause like

SQL
update project_task set description=@descrip,personnelresid=@resid,startdt=@startdt,completiondt=@completiondt,status=@status,lastupdatedt=@lastupdate,stage=@stage,creationdt=isnull(@creationdt,creationdt),taskpriority=@priority output inserted.taskname,inserted.managerid  where projectTaskid=@projecttaskid");


Now,taskname is in one table (project_task) and managerid is in another table (say "B").Can I fetch the data from two tables by any join?
Posted

The full form of UPDATE includes also FROM (optional)...That FROM can include any JOIN you familiar with from simple SELECT queries...
In the OUTPUT part of the query you can use any table from your UPDATE...FROM query...
SQL
UPDATE ...
SET ...
FROM table1
  LEFT JOIN table2 ON ...
OUTPUT
  INSERTED...,
  table1...,
  table2...
 
Share this answer
 
Comments
souvikcode 21-Jun-15 11:36am    
inserted.table1.col1 is giving error...
souvikcode 21-Jun-15 12:01pm    
your query is wrong.from clause will be after output clause.
update pt set pt.description=@descrip,pt.personnelresid=@resid,.... output inserted.taskname,pm.managerid from project_task pt left join project_master pm on pt.projectid=pm.projectid where pt.projectTaskid=@projecttaskid
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900