5 pts.
 How do I subtract 3 days from current date only when current day = 2, so that I retrieve the previous Fridays date?
I am new to using T-SQL, so there is probably an easy way to accomplish this, but I can't seem to get it right.  I want to retrieve the previous day's date (requires a weekday) to use as a comparsioin to a date field in the table, format is YYYYMMDD.  When the current date is a Monday, I need to subtract 3 days from current date, otherwise subtract 1 day.

Software/Hardware used:
T-SQL
ASKED: April 9, 2012  7:59 PM
UPDATED: April 10, 2012  2:07 PM

Answer Wiki:
Try this <pre>select date, DATEADD(dd,case when datename(dw, date) = 'monday' then -3 else -1 end, date) from table</pre> <a href="http://www.sql-tutorial.ru/en/book_tsql_datetime_functions.html">date/time functions</a>
Last Wiki Answer Submitted:  April 10, 2012  2:07 pm  by  msi77   1,610 pts.
All Answer Wiki Contributors:  msi77   1,610 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _