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


Create FInancial week Dynamic based on parameter


Create FInancial week Dynamic based on parameter

Author
Message
baseehkhan
baseehkhan
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
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
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16576 Visits: 17020
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)
baseehkhan
baseehkhan
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
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.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16576 Visits: 17020
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)
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24206 Visits: 37971
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.

Cool
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)
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