locked
How to calculate current financial year using stored procedure? RRS feed

  • Question

  • User-1016988731 posted

      Hi,

    I want to calculate the current financial year in my stored procedure and use it when generating a unique Id for the customer registring in my system.  Please help.


    Thanx in advance.


    Saturday, March 6, 2010 12:01 AM

Answers

  • User-2082239438 posted

    -- T-SQL financial year calculation
    DECLARE @BusinessDate datetime
    Set  @BusinessDate='2018-03-15'
    
    SELECT FiscalYear = CASE 
                        WHEN MONTH(@BusinessDate) < 4 THEN YEAR(@BusinessDate)-1
                        ELSE YEAR(@BusinessDate) END
                        
    -- 2017
    
    SET @BusinessDate  ='2018-05-15'
    
    SELECT FiscalYear = CASE 
                        WHEN MONTH(@BusinessDate) < 4 THEN YEAR(@BusinessDate)-1
                        ELSE YEAR(@BusinessDate) END
    
     -- 2018                   
    


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 6, 2010 12:36 AM

All replies

  • User-2082239438 posted

    -- T-SQL financial year calculation
    DECLARE @BusinessDate datetime
    Set  @BusinessDate='2018-03-15'
    
    SELECT FiscalYear = CASE 
                        WHEN MONTH(@BusinessDate) < 4 THEN YEAR(@BusinessDate)-1
                        ELSE YEAR(@BusinessDate) END
                        
    -- 2017
    
    SET @BusinessDate  ='2018-05-15'
    
    SELECT FiscalYear = CASE 
                        WHEN MONTH(@BusinessDate) < 4 THEN YEAR(@BusinessDate)-1
                        ELSE YEAR(@BusinessDate) END
    
     -- 2018                   
    


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 6, 2010 12:36 AM
  • User1867929564 posted

     try this,
    DECLARE @CurrrentYear varchar (4)
    DECLARE @NextYear varchar (4)
    declare @FiscalYear varchar(12)

    Select @CurrrentYear=Year(getdate())

    set @NextYear=@CurrrentYear+1

    set @FiscalYear=@CurrrentYear +' - '+@NextYear
    Select @FiscalYear as FiscalYear

    Saturday, March 6, 2010 1:34 AM