Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Create FInancial week Dynamic based on parameter Expand / Collapse
Author
Message
Posted Tuesday, May 14, 2013 7:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 4:28 AM
Points: 21, Visits: 98
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
Post #1452560
Posted Tuesday, May 14, 2013 8:18 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:03 PM
Points: 13,289, Visits: 12,136
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1452609
Posted Tuesday, May 14, 2013 11:18 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 4:28 AM
Points: 21, Visits: 98
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.
Post #1452919
Posted Wednesday, May 15, 2013 8:33 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:03 PM
Points: 13,289, Visits: 12,136
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1453129
Posted Wednesday, May 15, 2013 9:00 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 8:09 PM
Points: 23,270, Visits: 31,985
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.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1453160
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse