Update all the title in the TableA table with the TitleName in the TableB if there is a corresponding relationship in the TableB
Update as a Set = (Selectfrom aswhere=b.xid)
The above notation cannot be performed in MSSQL, so
We can use a function-disguised script
incoming parameters are the same
Update TableA Set =fn_getxtitle (ID)
Fn_getxtitle
ALTER FUNCTION [dbo].[Fn_getxtitle]( @id NVARCHAR( -)) RETURNS NVARCHAR( -) asBEGINDeclare @title nvarchar( -) Set @title =SelectB.titlename fromTableB asBwhereB.xid=@idRETURN @titleEnd
incoming parameters are different
--Create FUNCTION function
Create FUNCTION [dbo].[Fn_getdatafromoldve]( @OLDVE NVARCHAR( -) ,@Type NVARCHAR( -) ) RETURNS NVARCHAR( -) asBEGINDeclare @BO_ID nvarchar( -)Declare @NEWVE nvarchar( -)Declare @PjtNO_X nvarchar( -)IF @TYPE ='M' BEGIN Set @NEWVE =(Select Top 1Newve from [XXXX].[dbo].[mig_mapping1] whereOldve=@OLDVE andFIELDNAME='Pspix') if @NEWVE is not NULL begin Set @BO_ID =(Select Top 1bo_id from [XXXX].[dbo].[Mig_order_base] WHEREorder_id=@NEWVE) if @BO_ID is not NULL begin RETURN @BO_ID End Else begin RETURN @OLDVE End End Else begin RETURN @OLDVE End ENDIF @TYPE ='P' BEGIN Set @NEWVE =(Select Top 1Newve from [XXXX].[dbo].[mig_mapping1] whereOldve=@OLDVE andFIELDNAME='Pspid') if @NEWVE is not NULL begin RETURN @NEWVE End Else begin RETURN @OLDVE End ENDIF @TYPE ='PX' BEGIN Set @PjtNO_X =(Select Top 1Newve from [XXXX].[dbo].[mig_mapping1] whereOldve=@OLDVE andFIELDNAME='Pspix') if @PjtNO_X is not NULL begin RETURN @PjtNO_X End Else begin RETURN @OLDVE End END RETURN @OLDVEEND
--Executed script
update [ ". [ " . [ tb_prjmethod [ pjtno [ dbo ] . [ ] (pjtno, " p ' )
[SQL] The association in the MSSQL UPDATE statement