简体   繁体   English

SQL错误日期与int不兼容

[英]SQL Error date is incompatible with int

Can Some One help me with this please. 有人可以帮我这个忙吗? I was trying to use this Excel condition in SQL but I am getting error. 我试图在SQL中使用Excel条件,但出现错误。

EXCEL Condition = "=DATE(2017,MONTH(EOMONTH(B2,0)+1),DAY(EOMONTH(B2,0)+1))"

SQL Query = DATEFROMPARTS(YEAR(GETDATE()),CONVERT(Varchar,
(MONTH(EOMONTH(hiredate,0)+1)),120),CONVERT(Varchar,
(DAY(EOMONTH(HireDate,0)+1)),120)) as 'DATE'  

ERROR: Msg 206, Level 16, State 2, Line 1

Operand type clash: date is incompatible with int

Thank You in Advance 先感谢您

I guess you're trying to get the first day of the month after hiredate , but I can't tell for sure. 我想您正在尝试获取hiredate日期后的第一天的第一天,但​​我不能确定。

This MySQL expression generates that, using the handy-dandy LAST_DAY() function . 该MySQL表达式使用方便的LAST_DAY()函数生成该表达式。

      LAST_DAY(hiredate) + INTERVAL 1 DAY

If you want the first day of the month in which hiredate occurs, use this. 如果您想在hiredate月的第一天发生hiredate ,请使用此日期。

      LAST_DAY(hiredate) + INTERVAL 1 DAY - INTERVAL 1 MONTH

If you're working with SQL Server (the Microsoft product) this expression gets you the first day of the month in which hiredate occurs. 如果您使用的是SQL Server(Microsoft产品),则此表达式可让您获得hiredate日期的当月第一天。

   DATEFROMPARTS(YEAR(hiredate), MONTH(hiredate), 1)

This gets you the first day of the next month. 这使您下个月的第一天。

   DATEADD(MONTH, 1,DATEFROMPARTS(YEAR(hiredate), MONTH(hiredate), 1))

As you can see, it's different in SQL Server and MySQL. 如您所见,它在SQL Server和MySQL中有所不同。 Job security for data base hackers. 数据库黑客的工作安全性。 The built-in data handling functions deal correctly with stuff like 28, 29, 30, and 31-day months, and leap years, and all those calendar minutiae, so you don't have to. 内置的数据处理功能可以正确处理28、29、30和31天的月份,leap年以及所有这些日历细节,因此您不必这样做。

In Your Query Use DATEADD() Function OF SQL As Shown As Below,This May Work For You. 在查询中使用SQL的DATEADD()函数,如下所示,这可能对您有用。

Use 采用

CONVERT(Varchar,MONTH(DATEADD(dd,1,EOMONTH(GETDATE(),0))),120)

Instead Of 代替

(MONTH(EOMONTH(hiredate,0)+1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM