Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Last Date of the month

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2013-04-26 : 12:21:38
Hi All
I would like to write a query that will return all requests from Customer_infor table where the eligthrudate is someday between the month and not first and last day of the month

Sample Data
requestid EligThruDate
218584 12/27/12
221328 09/01/10
221340 12/31/09
221355 07/24/12


My query should not return becasue the eligthrudates are on the first or last day of the month and any other requests with other dates should be ignored

221328 09/01/10

221340 12/31/09


Need help

thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-04-26 : 12:42:23
Please put your data in a consumable format so you can run queries against it. Here is one (poor) solution:
DECLARE @Foo TABlE (requestid int, EligThruDate DATE)

INSERT @Foo VALUES
(218584, '12/27/12'),
(221328, '09/01/10'),
(221340, '12/31/09'),
(221355, '07/24/12')


SELECT *
FROM @Foo
WHERE
MONTH(EligThruDate) = MONTH(DATEADD(DAY, -1, EligThruDate))
AND MONTH(EligThruDate) = MONTH(DATEADD(DAY, 1, EligThruDate))
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2013-04-26 : 14:46:17
Sorry and thank You
quote:
Originally posted by Lamprey

Please put your data in a consumable format so you can run queries against it. Here is one (poor) solution:
DECLARE @Foo TABlE (requestid int, EligThruDate DATE)

INSERT @Foo VALUES
(218584, '12/27/12'),
(221328, '09/01/10'),
(221340, '12/31/09'),
(221355, '07/24/12')


SELECT *
FROM @Foo
WHERE
MONTH(EligThruDate) = MONTH(DATEADD(DAY, -1, EligThruDate))
AND MONTH(EligThruDate) = MONTH(DATEADD(DAY, 1, EligThruDate))


Go to Top of Page
   

- Advertisement -