Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Financial Month


Financial Month

Author
Message
Kartik M
Kartik M
SSC-Enthusiastic
SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)

Group: General Forum Members
Points: 168 Visits: 219
Comments posted to this topic are about the item Financial Month

Thanks & Regards,
Kartik M Kumar..
varshney4u
varshney4u
SSC Veteran
SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)

Group: General Forum Members
Points: 215 Visits: 191
Please provide details :-)
UMG Developer
UMG Developer
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2280 Visits: 2204
Am I missing something, or is the UDF code missing from the post?
varshney4u
varshney4u
SSC Veteran
SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)

Group: General Forum Members
Points: 215 Visits: 191
Yes, the UDF code missing from the post, please update ...
Kartik M
Kartik M
SSC-Enthusiastic
SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)

Group: General Forum Members
Points: 168 Visits: 219
Hi All,

I donno how the UDF code was missed while publishing, I update the code as a new article, however I'm providing the same here also..


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fn_FinMonth]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[Fn_FinMonth]
go
Create Function dbo.Fn_FinMonth(@MonthCode varchar(2))
Returns Varchar(2)
As
/*------------------------------------------------------------------------------------------------------------------------------------------
** SQLVersion : SQL 2000
** Function   : Fn_FinMonth
** Author    : Kartik M
** DateTime   : 29 January 2011 22:30
** Version   : 1.2
** Purpose   : To get the financial month from the respective calander month
** ToCheck   :
** Changes   : KM - 06 Feburary 2011 - Change the return type form Numeric to Varchar and add Leading Zeros to avoid problem while sorting
------------------------------------------------------------------------------------------------------------------------------------------*/
/*
-- Start of Debugging Stuff
   Declare @MonthCode varchar(2)
   Set @MonthCode = '02' -- Pass the Month Number as Input
-- End of Debugging Stuff
*/
Begin
   Declare @FinMonthC Varchar(2)
   Declare @IMonthCode int

   Set @IMonthCode = cast(@MonthCode as int)
   if @ImonthCode between 4 and 12
      Begin
         Set @FinMonthC = @IMonthCode-3
         Set @FinMonthC = Replicate('0', 2-len(@FinMonthC))+@FinMonthC
      End
      
   Else if @ImonthCode between 1 and 3
      Begin
          Set @FinMonthC = @IMonthCode+9
         Set @FinMonthC = Replicate('0', 2-len(@FinMonthC))+@FinMonthC
      End

Return @FinMonthC
End
--Select dbo.Fn_FinMonth ('05')
go



Thanks & Regards,
Kartik M Kumar..
Kartik M
Kartik M
SSC-Enthusiastic
SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)SSC-Enthusiastic (168 reputation)

Group: General Forum Members
Points: 168 Visits: 219
Please refer above code...

Thanks & Regards,
Kartik M Kumar..
ais.mech
ais.mech
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 333
Following is simple query for the same.

DECLARE @Cal_Month AS INT
SET @Cal_Month = 1
SELECT @Cal_Month Cal_Month,ISNULL(NULLIF((@Cal_Month+9)%12,0),12) Fin_Month

SET @Cal_Month = 3
SELECT @Cal_Month Cal_Month,ISNULL(NULLIF((@Cal_Month+9)%12,0),12) Fin_Month

SET @Cal_Month = 4
SELECT @Cal_Month Cal_Month,ISNULL(NULLIF((@Cal_Month+9)%12,0),12) Fin_Month

SET @Cal_Month = 12
SELECT @Cal_Month Cal_Month,ISNULL(NULLIF((@Cal_Month+9)%12,0),12) Fin_Month

hjackson67
hjackson67
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 90
Thanks for posting this, I was just about to write something similar when I came across your post.

There is one small thing that I wanted to mention: In the United States, companies have the option of selecting their own fiscal year. For example, my companies fiscal year is October 1st to September 30th of the following year.

The only proviso is that a company may not change their fiscal year without informing the regulatory authorities (IRS, SEC, etc).

So, I'm going to adapt your code to my companies fiscal year and call it good. Thanks!
Mitesh Oswal
Mitesh Oswal
Right there with Babe
Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)Right there with Babe (798 reputation)

Group: General Forum Members
Points: 798 Visits: 653





DECLARE @Varmonth CHAR(2)
SELECT @Varmonth = 04

select @Varmonth =datediff(mm,'1899/04/01',DATEADD(mm,CAST(@Varmonth AS INT) ,0))%12 +CASE WHEN CAST(@Varmonth AS INT) = 3 THEN 12 ELSE 0 END
      
select @Varmonth = REPLICATE('0',2-LEN(@Varmonth))+@Varmonth

select @Varmonth







Regards,
Mitesh OSwal
+918698619998
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

Group: General Forum Members
Points: 8606 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search