DECLARE @SINKKNO varchar (one), @KYOKAYMD varchar (8), @LASTUPDATEID varchar (5), @LASTUPDPGID varchar (7), @SYANAISEQNO varchar (8), @TUKAN_TOKUISAKI varchar, @TUKAN_TOKUISAKI_INP varchar, @NINUSIKIJI varchar, @NINUSISECCD varchar (one), @NINUSIREFNO varchar (15); set @SINKKNO = ' 43935442710 ' set @KYOKAYMD = ' 20170920 ' set @LASTUPDATEID = ' Batch ' SE t @LASTUPDPGID = ' BC02501 ' set @SYANAISEQNO = ' 1199s002 ' set @TUKAN_TOKUISAKI = ' 1120 0010358669000 ' set @TUKAN_TOKUISAKI_INP = ' 1000071j0000 ' set @NINUSIKIJI = ' Ninusikiji ' SET @NINUSISECCD = ' NINUSISECCD ' set @NINUSIREFNO = ' ninusireference '; update &N Bsp c_t_exp set [sinkkno] = @SINKKNO, [Kyokay MD] = @KYOKAYMD, [LASTUPDATEYMD] = GETDATE (), [Lastupdateid] = @LAST Updateid,&nbsP [Lastupdpgid] = @LASTUPDPGID, [Tukan_tokuisaki] = @TUKAN_TOKUISAKI, [TUKAN_TOKUISAKI_INP] = @TUKAN_TOKUISAKI_INP, [Ninusikiji] = case & nbsp when ( P.[ninusikiji) is null &nbs P or P.[ninusikiji] = " ) then @NINUSIKIJI ELSE p.[ninusikiji] end, [Ninusi SECCD] = (case when P.[ni NUSISECCD] is null or P.[NINUSISECCD] = " &NBSP ; ) then @NINUSISECCD ELSE p.[ninusiseccd] END), & nbsp [NINUSIREFNO] = (case when ( &NBSP ; P.[NINUSIREFNO] is null or p.[ninusirefno] = ' ) then @NINUSIREFNO ELSE p.[ninusirefno] END)From C_t_exp INNER joins C_t_exp P on C_t_exp. Usyutdaino = P.usyutdaino WHERE c_t_exp. Syanaiseqno = @SYANAISEQNO and c_t_exp. DELSGN = 0 and 1 = (SELECT COUNT (T1). Usyutdaino) from [C_t_exp] T1 WHERE T1. Syanaiseqno = @SYANAISEQNO and T1. DELSGN = 0)
A Sample to use Update, Innerjoin, When/case, Exists in SQL Server