我正在尝试使用Case in Update查询,它给出了一个错误,即case附近有一个不正确的语法。我不确定在哪里?!这是在SQL 2005
中我将日期发送到存储过程。如果发送的日期是'01 / 01/1905',则必须保存null,否则输入的实际日期。我真的不确定这句话有什么问题。
Update Manifest set Notes = @Notes, IsCustom = @IsCustom,
CASE WHEN @ProofSent = CONVERT(datetime, '01/01/1905') THEN NULL ELSE @ProofSent END,
CASE WHEN @ProofApproved = CONVERT(datetime, '02/01/1905') THEN NULL ELSE @ProofApproved END
提前致谢!
答案 0 :(得分:1)
您尚未声明应将其设置为哪个列:
Update Manifest set Notes = @Notes, IsCustom = @IsCustom,
ProofSent = CASE WHEN @ProofSent = CONVERT(datetime, '01/01/1905') THEN NULL ELSE @ProofSent END,
ProofApproved = CASE WHEN @ProofApproved = CONVERT(datetime, '02/01/1905') THEN NULL ELSE @ProofApproved END
答案 1 :(得分:0)
必须是这样的:
Update Manifest set Notes = @Notes, IsCustom = @IsCustom,
Column1 =
CASE WHEN @ProofSent = CONVERT(datetime, '01/01/1905') THEN NULL
ELSE @ProofSent END,
Column2=
CASE WHEN @ProofApproved = CONVERT(datetime, '02/01/1905') THEN NULL
ELSE @ProofApproved END