如何从output子句中的两个表中获取数据 [英] how to fetch data from two tables in output clause

查看:69
本文介绍了如何从output子句中的两个表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的更新查询中,我想在输出子句中获取数据,例如



In my update query I want to fetch data in output clause like

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");





现在,taskname在一个表(project_task)中,而managerid在另一个表中(比如B) )。我可以通过任何连接从两个表中获取数据吗?



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?

推荐答案

UPDATE的完整形式还包括FROM(可选)...... FROM可以包含任何从简单的SELECT q加入你熟悉的ueries ...

在查询的OUTPUT部分,您可以使用UPDATE ... FROM查询中的任何表...

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...
UPDATE ...
SET ...
FROM table1
  LEFT JOIN table2 ON ...
OUTPUT
  INSERTED...,
  table1...,
  table2...


update pt set pt.description = @ descrip,pt.personnelresid = @ resid,.... output inserted来自project_task的.taskname,pm.managerid pt在pt.projectid = pm.projectid上加入project_master pm,其中pt.projectTaskid = @ projecttaskid
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


这篇关于如何从output子句中的两个表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆