如何解决错误消息206,Niveau 16,État2,Ligne 91 d'opérandes的类型冲突:日期和日期不兼容avec tinyint
我遇到错误:
错误消息206,Niveau 16,État2,Ligne 91
Conféde type d'opérandes:日期est不兼容avec tinyint
代码:
CREATE TABLE reservation
(
codres int PRIMARY KEY IDENTITY(1,1),numcl int FOREIGN KEY REFERENCES client,numt int FOREIGN KEY REFERENCES typesejour,codho int FOREIGN KEY REFERENCES hotel,datedebut date,datefin date,montant float DEFAULT 0,CONSTRAINT ck CHECK (datefin > datedebut)
)
ALTER TABLE reservation
ADD CONSTRAINT ch1 DEFAULT 0 FOR montant;
UPDATE reservation
SET montant = 0.9 * montant
WHERE MONTH(datedebut) IN (9,10)
AND (datefin) IN (9,10);
解决方法
这是您的where
语句的update
子句:
where month(datedebut) in (9,10) and (datefin) in (9,10)
第二个条件引发错误,因为您试图将date
(datefin
)与整数列表(9
和10
)进行比较。 / p>
大概是您的意思:
where month(datedebut) in (9,10) and month(datefin) in (9,10)
请注意,比较这样的日期效率很低。尽可能使用直接日期比较会更好。假设您想要去年的9月和10月,则可以这样写:
where
datedebut >= '20190901'
and datedebut < '20191101'
and datefin >= '20190901'
and datefin < '20191101'
当然,如果您希望每年的9月和10月,那么表达是正确的选择。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。