Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-01-17 : 09:20:21
|
I need to write a case statement using 5 Business Days including todays date(Business Days being Monday-Friday)I have a table Customer_Processing using which I need to write a stored procedure and struggling with the select statementBelow is the Case Statement and need help for the case statement partSelect Requestid,ReportNo,AvailableDate = CaseWhen [AvailableDate] is in the next 5 businessdays including today then “Active”When [AvailableDate] Is in the past then “Not Active – Past”When [AvailableDate] is in the future(More than 5 business Days including today) then “Not Active – Future”EndFrom Customer_ProcessingWhere (REQNO = @RQNO) and (ReportNo = @RPNO) ThanksJim |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-17 : 09:36:48
|
Would something like this work for you? It would not take care of holidays that fall on weekdays. If you need to accommodate that, you would need a calendar table.DECLARE @dt DATETIME;SET @dt = '20120121'; SELECT CASE WHEN N < 0 THEN 'Not Active – Past' WHEN N >= 7 THEN 'Not Active – Future' ELSE 'Active' ENDFROM( SELECT DATEDIFF(DAY,GETDATE(),@dt) AS N ) S |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-01-17 : 10:07:22
|
| At this time worried only about weekend holidaysHow would i use the case statement you have provided with my scenario |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-17 : 10:24:03
|
| [code]SELECT Requestid, ReportNo, AvailableDate = CASE WHEN DATEDIFF(DAY,GETDATE(),[AvailableDate]) < 0 THEN 'Not Active Past' WHEN DATEDIFF(DAY,GETDATE(),[AvailableDate]) >= 7 THEN 'Not Active Future' ELSE 'Active' ENDFROM Customer_ProcessingWHERE (REQNO = @RQNO) AND (ReportNo = @RPNO);[/code] |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-01-17 : 10:45:08
|
Thank You.quote: Originally posted by sunitabeck
SELECT Requestid, ReportNo, AvailableDate = CASE WHEN DATEDIFF(DAY,GETDATE(),[AvailableDate]) < 0 THEN 'Not Active Past' WHEN DATEDIFF(DAY,GETDATE(),[AvailableDate]) >= 7 THEN 'Not Active Future' ELSE 'Active' ENDFROM Customer_ProcessingWHERE (REQNO = @RQNO) AND (ReportNo = @RPNO);
|
 |
|
|
|
|
|
|
|