Sunday, February 12, 2012

Business Day Calendar table get x days in the past

I have a table of dates and a second column for bit. I need to know the
date of X business days ago
declare @.dateIn datetime, @.days int
set @.datein = '5-17-2006'
set @.days=5
select A.bdate
From BusinessCALendar as A
Inner Join BusinessCALendar as B
on A.bdate <= B.bdate
and A.btype=B.btype
Where A.btype= 1 -- identify a work day as 1
and A.bdate < @.datein
Group by A.bdate
Having count(*) = @.days
My having line voids any return of data. I think this is close, but how do
you walk backwards in rows?
TIAhttp://www.aspfaq.com/2519
"_Stephen" <srussell@.electracash.com> wrote in message
news:OBe6%23oceGHA.4532@.TK2MSFTNGP02.phx.gbl...
>I have a table of dates and a second column for bit. I need to know the
>date of X business days ago
> declare @.dateIn datetime, @.days int
> set @.datein = '5-17-2006'
> set @.days=5
> select A.bdate
> From BusinessCALendar as A
> Inner Join BusinessCALendar as B
> on A.bdate <= B.bdate
> and A.btype=B.btype
> Where A.btype= 1 -- identify a work day as 1
> and A.bdate < @.datein
> Group by A.bdate
> Having count(*) = @.days
>
> My having line voids any return of data. I think this is close, but how
> do you walk backwards in rows?
>
> TIA
>|||http://www.aspfaq.com/2519
"_Stephen" <srussell@.electracash.com> wrote in message
news:OBe6%23oceGHA.4532@.TK2MSFTNGP02.phx.gbl...
>I have a table of dates and a second column for bit. I need to know the
>date of X business days ago
> declare @.dateIn datetime, @.days int
> set @.datein = '5-17-2006'
> set @.days=5
> select A.bdate
> From BusinessCALendar as A
> Inner Join BusinessCALendar as B
> on A.bdate <= B.bdate
> and A.btype=B.btype
> Where A.btype= 1 -- identify a work day as 1
> and A.bdate < @.datein
> Group by A.bdate
> Having count(*) = @.days
>
> My having line voids any return of data. I think this is close, but how
> do you walk backwards in rows?
>
> TIA
>|||> http://www.aspfaq.com/2519
Thanks. I got what was needed there.

No comments:

Post a Comment