aajay
Technical User
- Oct 28, 2004
- 36
How can I get data for every fifth year from table
Hope you might have done that also
thanks
Hope you might have done that also
thanks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
declare @StartYear int
set @StartYear = 2000
select Columns
from YourTable(nolock)
where datepart(yy, YourDateColumn) = @StartYear AND (datepart(yy, YourDateColumn) % 5) = 0
declare @StartYear int
set @StartYear = 2000
select Columns
from YourTable(nolock)
where datepart(yy, YourDateColumn) [b]>=[/b] @StartYear AND (datepart(yy, YourDateColumn) % 5) = 0
[COLOR=blue]select[/color] [COLOR=#FF00FF]Columns[/color]
[COLOR=blue]from[/color] YourTable(nolock)
[COLOR=blue]where[/color] [COLOR=#FF00FF]datepart[/color](yy, YourDateColumn) >= @StartYear
AND ([COLOR=#FF00FF]datediff[/color](yy, @StartYear, YourDateColumn) % 5) = 0
[COLOR=blue]declare[/color] @rDate [COLOR=#FF00FF]datetime[/color]
[COLOR=blue]set[/color] @rDate = [COLOR=red]'5/30/2006'[/color]
[COLOR=blue]declare[/color] @rMod [COLOR=blue]int[/color]
[COLOR=blue]Select[/color] @rMod = dbo.GetWUFiscalYear(@rDate) % 5
[COLOR=blue]select[/color] sum(AnnualFundGiven),
sum(AnnualFundGifts),
sum(ActualMatchAmount),
sum(SoftCreditGiven),FiscalYear
[COLOR=blue]from[/color] vwGiving_Summary_FY v
[COLOR=blue]where[/color] FiscalYear % 5 = @rMod
[COLOR=blue]group[/color] [COLOR=blue]by[/color] FiscalYear