mssql在update中用join 用from

select * from  TB_PD_BUG_DATA
left JOIN
dbo.TB_BUG ON dbo.TB_PD_BUG_DATA.PDBD_BUG_ID = dbo.TB_BUG.BUG_ID
left JOIN
dbo.TB_PROCESS ON dbo.TB_BUG.BUG_PRC_ID = dbo.TB_PROCESS.PRC_ID
where prc_name like '%asdf)%' and pdbd_prc_dept_id=0

 ---------------------------------------------------------------------------------
update  TB_PD_BUG_DATA set pdbd_prc_dept_id=37
from TB_PD_BUG_DATA
left JOIN
dbo.TB_BUG ON dbo.TB_PD_BUG_DATA.PDBD_BUG_ID = dbo.TB_BUG.BUG_ID
left JOIN
dbo.TB_PROCESS ON dbo.TB_BUG.BUG_PRC_ID = dbo.TB_PROCESS.PRC_ID
where prc_name like '%asdf%' and pdbd_prc_dept_id=0
------------------
--- update不能同时更新多个表

 

---------------------------------------------------

 

代码
-- --将b表的某字段改成与a表的某字段相同的数据。 
create   table  a
(
 a1 
varchar ( 30 ),
 a2 
varchar ( 30 )
)
go
create   table  b
(
   b1 
varchar ( 30 ),
   b3 
varchar ( 30 ),
   b2 
varchar ( 40 )
)
insert   into  a  values ( ' 6 ' , ' 66666 ' )
select   *   from  a
select   *   from  b
update  b  set  b.b2 = a.a2  from  a,b  where (a.a1 = b.b1)

 

 

你可能感兴趣的:(update)