Create FInancial week Dynamic based on parameter

  • Hi all,

    I need to generate the financial week but in my case the starting month of the financial week ill get change for that am using the parameter to get the starting month.Please help me to get that.

    This is static query in which i consider April as the starting month. like i need to generate.

    declare @date datetime='2013-4-01'

    select CASE WHEN DATEPART(WW,@date)<=13 THEN 40+DATEPART(WW,@date) ELSE DATEPART(WW,@date)-13 END

    Regards,

    Basee

  • baseehkhan (5/14/2013)


    Hi all,

    I need to generate the financial week but in my case the starting month of the financial week ill get change for that am using the parameter to get the starting month.Please help me to get that.

    This is static query in which i consider April as the starting month. like i need to generate.

    declare @date datetime='2013-4-01'

    select CASE WHEN DATEPART(WW,@date)<=13 THEN 40+DATEPART(WW,@date) ELSE DATEPART(WW,@date)-13 END

    Regards,

    Basee

    I don't quite understand what you are trying to do here. Can it explain it more clearly?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • I want to create the fiscal week for the date.In my case the starting month of the fiscal year keep change it depends on user.

    For that i need help. Above static query is to get the fiscal week for that the starting month is 4.

    Instead of that i would like to use a parameter to get month. By using that is should generate week number.

  • baseehkhan (5/14/2013)


    I want to create the fiscal week for the date.In my case the starting month of the fiscal year keep change it depends on user.

    For that i need help. Above static query is to get the fiscal week for that the starting month is 4.

    Instead of that i would like to use a parameter to get month. By using that is should generate week number.

    Still not totally sure what you are trying to do but if you could post ddl, sample data and desired output based on the sample data we can figure it out.

    Please take a few minutes and read the first article in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • baseehkhan (5/14/2013)


    I want to create the fiscal week for the date.In my case the starting month of the fiscal year keep change it depends on user.

    For that i need help. Above static query is to get the fiscal week for that the starting month is 4.

    Instead of that i would like to use a parameter to get month. By using that is should generate week number.

    I have to agree with Sean, I still can't figure out exactly what you are looking for here. With that I wouldn't know where to start to help. The code you originally posted returns a 1 for 2013-04-01, but that doesn't help understand what should be returned for other dates, or what day of the week a fiscal week starts on. These are just a couple of things you still need to explain if we are going to try and help.

    Please remember, we can't see what you see, we don't know your systems or applicatioins, or data. We can only work off what you provide.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply