我在SQL Server中有两个日期 - [O/R COMPLETE DATE]
和[O/R SHIP BY]
。我想检查[O/R COMPLETE DATE]
是否晚于[O/R SHIP BY]
,如果是,我想显示一条消息Overwrite shipBy date must be later than Overwrite Completed date
。
有可能吗?
答案 0 :(得分:1)
这个怎么样?
CREATE TABLE OVERWRITE
(OVERWRITEID int
,[O/R COMPLETE DATE] date
,[O/R SHIP BY] date
,[SHIP INSTRUCTIONS] AS
CASE WHEN [O/R COMPLETE DATE] > [O/R SHIP BY]
THEN 'Overwrite shipBy date must be later than Overwrite Completed date'
ELSE
'Overwrite shipBy date and Overwrite Completed dates are valid'
END
)
INSERT INTO OVERWRITE
VALUES (1,'1/1/2017', '6/1/2017'), (2, '11/1/2017', '10/1/2017')
SELECT *
FROM OVERWRITE
触发器不是为输出而设计的;如前所述,建议客户端应用程序发送消息。数据库中坏数据的第一道防线是前端应用程序。