SQL Reporting - Calculate Week number of Year

Hi!

I am working on an sql report that should show the scheduled count date for each part.

1. This gives me the next count date in days:  DATEDIFF(day, C.LAST_COUNT_DATE, GETDATE()) - C.COUNT_FREQ

2. I have another table that will give me the actual date that the part was counted for the current year.

3.  If a part is scheduled to be counted every four years, I need to be able to display the  dates  that it was counted then the next three scheduled count dates.

The schedule should look like:

Part_ID                 ABC_CODE        Count Date            Next Count Date              NextCountDate         NextCountDate

888*FRP*66*U                    D                   3/20/2015                  3/20/2019                          3/20/2023                  3/20/2027
                                                                           C                            X                                               X                                   X



777*568*22                        A                    1/2/2015                    6/2/2015                            1/2/2016                      6/2/2016
                                                                          C                                 X                                         X                                     X

Open in new window



The 'X'  and 'C'   stand for Counted and not yet counted.  If the item has been counted according to the appropriate count frequency, I want to show  a 'C'.
Annette Wilson, MSISSr. Programmer AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark ElySenior Coldfusion DeveloperCommented:
You should use DatePart to get the week of the year instead.  DATEPART ( datepart , date )

DATEPART(week, CountDate) AS WeekOfTheYear

https://msdn.microsoft.com/en-us/library/ms174420.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
technette, do you still need help with this question?
0
Annette Wilson, MSISSr. Programmer AnalystAuthor Commented:
I need help in a different way.  I will post another question.  Thank you Vitor.
0
Annette Wilson, MSISSr. Programmer AnalystAuthor Commented:
Thank you.  This was a quick and workable solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.