I have to calculate date before two days based on the condition .
Example date = ‘2012-09-01’ then @date should be ‘2012-08-30’ but here if 2012-08-31 is not working day then @date should be ‘2012-08-29’.
Could you please help me on this
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your question though apparently seems to be simple, but not so as there are many test cases involved in it (at least I have interpreted in that way). Let me first write the query (I assume you are using Sql Server 2005+)
CASE 1:Input date is 1st Sept(2012-09-01) and the immediate previous date’s WorkDayCount = 0
Result:
2012-08-29Reason: Since August 31st’s WorkDayCount = 0, so the working date will be 29th August
CASE 2: Input date is 1st Sept(2012-09-01) and the August 31st + August 30th WorkCount = 0.
Result:
2012-08-28CASE 3:Input date is 1st Sept(2012-09-01) and the immediate previous date’s WorkDayCount = 1
Result:
2012-08-30Kindly correct me if any of the assumptions/test cases are incorrect.
Let me know your concern.