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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Get Next Period, Ranging between days

Author  Topic 

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2011-02-03 : 04:13:13
Good Day,

I have a SSIS String Variable: Period

In my query i have to determine the next month period with date ranging between the 5th & 7th of the next period from Var:Period

Var:Period = 2010.12

I need to range on dates being 05/01/2011 and 07/01/2011

Please Assist

matty
Posting Yak Master

161 Posts

Posted - 2011-02-03 : 04:25:10
Is this what you want?

declare @p varchar(20)
set @p = '2010.12'
select @p = CONVERT(datetime,@p + '.01')
select DATEADD(m,5,@p) AS StartDate,DATEADD(mm,7,@p) AS EndDate
Go to Top of Page

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2011-02-03 : 04:45:29
Thank You, I get the result i'm looking for but it does not work to well when Var:Period changes

set @p = '2010.12'
result: 2011-05-01 00:00:00.000 & 2011-07-01 00:00:00.000

set @p = '2011.01'
result: 2011-06-01 00:00:00.000 & 2011-08-01 00:00:00.000

Should not only be for 2010.12 but for any month, not to sure about the adding of the '.01'

?
Go to Top of Page

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2011-02-03 : 06:08:42
Thank You Very Much, i got it going by adding day

declare @p varchar(20)
set @p = '2010.12'
select @p = CONVERT(datetime,@p + '.01')

select DATEADD(day,4,DATEADD(month,1,@p)) AS StartDate,DATEADD(day,11,DATEADD(month,1,@p)) AS EndDate
Go to Top of Page

matty
Posting Yak Master

161 Posts

Posted - 2011-02-03 : 06:12:14
What should be the date range when Var:Period is 2011.01?
Go to Top of Page
   

- Advertisement -