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.
| Author |
Topic |
|
jemacc
Starting Member
42 Posts |
Posted - 2004-10-04 : 17:26:22
|
| Hi all,I am try to get the fiscal year based on the current date. I have specified my current fiscal month. Part One1-If the current month >= 10 add 1 year as nextyear2-If the current month <= 10 subtract 1 year lastYearPart twoWhen the #1 statement is true then the results set should be"This year" -"NextYear" =last 2 digits are a stringWhen the #2 statement is true then the results set should be"This year" -"LastYear" =last 2 digits are a stringany help will be greatly appreciated. Getting the results from part one is most important to me. Here is what I have so farcreate PROCEDURE dbo.FiscalYear ASSet NOCOUNT Ondeclare @MonDate char(5),@begMonth char(2),@year char(4)select @begMonth=datepart(yy,getdate())set @begMonth = isNull(@begMonth,1)if len(rtrim(@begMonth)) = 1beginset @begMonth = '10' + rtrim(@begMonth)endif @begmonth >='10'set @Year= datepart(yy,getdate()+1)if @begmonth <'10'set @year = datepart(yy,getdate()-1)set @MonDate = @begMonth --+ '-01'select @MonDate as FiscalMonth,@year as FiscalYear |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2004-10-05 : 00:01:14
|
i think i read a similar post just last week, search the forum, and from what i remember, there was a definitive answer. |
 |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-10-05 : 01:04:47
|
| [code]select datename(m,getdate()) FiscalMonth,right(datename(yy,dateadd(yy,case when month(getdate())>=10 then 1 else -1 end,getdate())),2) FiscalYear[/code] |
 |
|
|
jemacc
Starting Member
42 Posts |
Posted - 2004-10-06 : 02:31:25
|
| Thank you very much |
 |
|
|
|
|
|
|
|