SQL Fiddle Demo .
:
CREATE TABLE Locations(
effective_date DATETIME
)
INSERT INTO Locations
VALUES('2014-01-01')
INSERT INTO Locations
VALUES('2014-01-02')
INSERT INTO Locations
VALUES('2014-01-31')
, , effective_date .
SELECT effective_date FROM Locations
WHERE
DATEPART(day, effective_date) <> 1
AND DATEPART(day, effective_date) <>
DATEPART(day, DATEADD(second,-1,DATEADD(month, DATEDIFF(month,0,effective_date)+1,0)))
January, 02 2014 00:00:00+0000 .
- , , :
DECLARE @sampleDate DATETIME
SET @sampleDate = '2014-01-02'
SELECT DATEDIFF(month,0,@sampleDate) + 1
SELECT DATEADD(month, DATEDIFF(month,0,@sampleDate)+1,0)
SELECT DATEADD(second,-1,DATEADD(month, DATEDIFF(month,0,@sampleDate)+1,0))
SELECT DATEPART(day, DATEADD(second,-1,DATEADD(month, DATEDIFF(month,0,@sampleDate)+1,0)))