操作数数据类型日期对于减算子无效 [英] Operand data type date is invalid for subtract operator

查看:515
本文介绍了操作数数据类型日期对于减算子无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表中有一个名为 [LastDate]并带有DataType Date 的字段。我将编写一个计算 [LastDate] - @ PassedParameter 的函数,但会发生错误:

 操作数数据类型日期对于减算子无效。 

我不知道为什么?

hara是函数:

$ pre $ CREATE FUNCTION Salman(@Date date)
RETURNS TABLE
AS
RETURN


SELECT TOP 1000 [ID]
,[名称]
,[LastDate]
,[规则] $ b $ ([LastDate] - @ Date)%[Rule] = 0



解决方案

您可以尝试使用 DATEDIFF函数

  DATEDIFF(datepart,startdate,enddate)

像这样:

 其中DATEDIFF(dd,LastDate,@ Date)%[Rule] = 0 
^^ - - 无论你想要什么 - 将其更改为毫米,qq。


I have a field in my table called [LastDate] with DataType Date. and I am going to write a function which compute the [LastDate]-@PassedParameter, but the error happen :

Operand data type date is invalid for subtract operator.

I don't know why?

hara is the function:

CREATE FUNCTION Salman( @Date  date )
RETURNS TABLE 
AS
RETURN 
(

SELECT TOP 1000 [ID]
      ,[Name]
      ,[LastDate]
      ,[Rule]
      ,[CoA]
  FROM [Scheduling_Employee].[dbo].[Group]
  where ([LastDate]-@Date)%[Rule]=0  
)
GO

解决方案

You may try using the DATEDIFF function.

DATEDIFF ( datepart , startdate , enddate )

So in your case you may change like this:

where DATEDIFF(dd,LastDate,@Date)%[Rule]=0
               ^^--Change this to mm,qq whatever you want.

这篇关于操作数数据类型日期对于减算子无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆