DateTime如果传递数据则应更新,否则使用已保存的原始值更新它。此更新无效
DECLARE @FolderStatusDate DATETIME = NULL
SET @FolderStatusDate = '2012-07-04 14:09:04.043'
UPDATE CM.PfmFolder
SET
FolderStatusDate = ISNULL(@FolderStatusDate, FolderStatusDate)
WHERE Id = @Id
答案 0 :(得分:1)
为什么不将NULL
的支票移到WHERE
条款?
DECLARE @FolderStatusDate DATETIME = NULL
SET @FolderStatusDate = '2012-07-04 14:09:04.043'
UPDATE CM.PfmFolder
SET
FolderStatusDate = @FolderStatusDate
WHERE Id = @Id
AND @FolderStatusDate IS NOT NULL
答案 1 :(得分:0)
你也可以这样做
DECLARE @FolderStatusDate DATETIME = NULL
SET @FolderStatusDate = '2012-07-04 14:09:04.043'
UPDATE CM.PfmFolder
SET
FolderStatusDate = case when ISNULL(@FolderStatusDate, '') = ''
then FolderStatusDate else @FolderStatusDate end
WHERE Id = @Id
答案 2 :(得分:0)
对 Hitesh Salian 回答
的轻微修改 DECLARE @FolderStatusDate DATETIME = NULL
SET @FolderStatusDate = '2012-07-04 14:09:04.043'
UPDATE CM.PfmFolder
SET
FolderStatusDate = case @FolderStatusDate is Null
then FolderStatusDate else @FolderStatusDate end
WHERE Id = @Id