A Sample To use Update, InnerJoin, When/Case, Exists in SQL Server
Posted tomclock
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A Sample To use Update, InnerJoin, When/Case, Exists in SQL Server相关的知识,希望对你有一定的参考价值。
DECLARE @SINKKNO varchar(11),
@KYOKAYMD varchar(8),
@LASTUPDATEID varchar(5),
@LASTUPDPGID varchar(7),
@SYANAISEQNO varchar(8),
@TUKAN_TOKUISAKI varchar(17),
@TUKAN_TOKUISAKI_INP varchar(12),
@NINUSIKIJI varchar(10),
@NINUSISECCD varchar(11),
@NINUSIREFNO varchar(15)
;
SET
@SINKKNO = ‘43935442710‘
SET
@KYOKAYMD = ‘20170920‘
SET
@LASTUPDATEID = ‘batch‘
SET
@LASTUPDPGID = ‘BC02501‘
SET
@SYANAISEQNO = ‘1199S002‘
SET
@TUKAN_TOKUISAKI = ‘11200010358669000‘
SET
@TUKAN_TOKUISAKI_INP = ‘1000071J0000‘
SET
@NINUSIKIJI = ‘NINUSIKIJI‘
SET
@NINUSISECCD = ‘NINUSISECCD‘
SET
@NINUSIREFNO = ‘NINUSIReference‘;
UPDATE
C_T_EXP
SET
[SINKKNO] = @SINKKNO,
[KYOKAYMD] = @KYOKAYMD,
[LASTUPDATEYMD] = GETDATE(),
[LASTUPDATEID] = @LASTUPDATEID,
[LASTUPDPGID] = @LASTUPDPGID,
[TUKAN_TOKUISAKI] = @TUKAN_TOKUISAKI,
[TUKAN_TOKUISAKI_INP] = @TUKAN_TOKUISAKI_INP,
[NINUSIKIJI] = CASE
WHEN(
P.[NINUSIKIJI] IS NULL
OR P.[NINUSIKIJI] = ‘‘
) THEN @NINUSIKIJI
ELSE P.[NINUSIKIJI]
END,
[NINUSISECCD] = (CASE
WHEN(
P.[NINUSISECCD] IS NULL
OR P.[NINUSISECCD] = ‘‘
) THEN @NINUSISECCD
ELSE P.[NINUSISECCD]
END),
[NINUSIREFNO] =( CASE
WHEN(
P.[NINUSIREFNO] IS NULL
OR P.[NINUSIREFNO] = ‘‘
) THEN @NINUSIREFNO
ELSE P.[NINUSIREFNO]
END)
FROM C_T_EXP
INNER JOIN 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的主要内容,如果未能解决你的问题,请参考以下文章
MySQL: You are using safe update mode and you tried to update a table without a WHERE that uses a KE
mysqlworkbench 执行update语句报错:You are using safe update mode and you tried to update a table without a
[Yarn] Use yarn up to Update Dependencies In A Yarn Workspace
mysql 报错:Error Code: 1175. You are using safe update mode and you tried to update a table without a
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE(示例代