本文介绍了帮助:过滤日期时间SQL列的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!谁能告诉我这个代码我做错了什么?

目标是按月从表 Sched 中过滤 SchedStart 列。 SchedStart采用DateTime格式(yyyy / MM / dd hh:mm:ss)。例如,选择SchedStart具有月份= 11(11月)的行。

此代码返回null gridview:

Hi! Could anyone tell me what am I doing wrong with this code?
The goal is to filter the column SchedStart from the table Sched by month. SchedStart is in a DateTime format ("yyyy/MM/dd hh:mm:ss"). For example, select the rows in which SchedStart has a month that is = 11(November).
This code returns a null gridview:

SELECT SchedID FROM Sched WHERE (SchedStart = MONTH(SchedStart))



虽然这个给了我一个错误(下面)


While this one gives me an error(below)

SELECT SchedID FROM Sched WHERE (SchedStart = (DATEPART(MM, SchedStart) = 11))




SQL错误:

SQL执行错误。

执行的SQL语句:SELECT SchedID FROM Sched WHERE(SchedStart =(DATEPART(MM,SchedStart)= 11))

错误来源:.Net Sql客户端数据提供者

错误消息:'='附近的语法不正确

SQL Execution Error.
Executed SQL statement: SELECT SchedID FROM Sched WHERE (SchedStart = (DATEPART(MM, SchedStart ) = 11))
Error Source: .Net Sql Client Data Provider
Error Message: Incorrect syntax near '='





请告诉我我做错了什么:(谢谢!



Please tell me what am I doing wrong :( Thanks!

推荐答案



这篇关于帮助:过滤日期时间SQL列的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 18:40