user3408399
user3408399

Reputation: 109

Output data from current month?

I have this table and i want to ge the data from current month. This is the table:

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 
    (

I want to get the data where status=1 and execoffice_status=0 and the current date.I want to use the approveddata column to get the date. Right now I have

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

I have Microsoft sql server 2008

Microsoft SQL Server Management Studio 10.0.2531.0

Upvotes: 0

Views: 47

Answers (2)

Pragnesh Khalas
Pragnesh Khalas

Reputation: 2898

It is simple:

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

Upvotes: 1

rory.ap
rory.ap

Reputation: 35308

Add AND MONTH([approveddate]) = MONTH(GETDATE()) AND YEAR([approveddate]) = YEAR(GETDATE()) to your where clause, assuming [approveddate] is the date you're interested in.

Upvotes: 2

Related Questions