当月的输出数据?

时间:2014-04-15 17:10:36

标签: sql sql-server-2008

我有这张表,我想从当月开始计算数据。 这是表格:

CREATE TABLE [dbo].[CSEReduxResponses](
        [response_id] [int] IDENTITY(1,1) NOT NULL,
        [submitterdept] [int] NOT NULL,
        [commentdate] [datetime] NOT NULL,
        [status] [int] NOT NULL,
        [approvedby] [int] NULL,
        [approveddate] [datetime] NULL,
            [execoffice_approvedby] [int] NULL,

     CONSTRAINT [PK_CSE_Responses] PRIMARY KEY CLUSTERED 
    (

我想把数据拿到哪里 status = 1和execoffice_status = 0以及当前日期。我想使用approveddata列来获取日期。 现在我有

select * from CSEReduxResponses WHERE STATUS=1 AND EXECOFFICE_STATUS=0;

我有Microsoft sql server 2008

Microsoft SQL Server Management Studio 10.0.2531.0

2 个答案:

答案 0 :(得分:2)

AND MONTH([approveddate]) = MONTH(GETDATE()) AND YEAR([approveddate]) = YEAR(GETDATE())添加到您的where子句中,假设[approveddate]是您感兴趣的日期。

答案 1 :(得分:1)

很简单:

SELECT * 
FROM   CSEReduxResponses 
WHERE  STATUS = 1 
AND    EXECOFFICE_STATUS = 0;
AND    MONTH(commentdate) = MONTH(GETDATE())
AND    YEAR(commentdate) = YEAR(GETDATE())