Question : Sql 2008 Query


I need to select the date of a previous Wednesday given a date and the next Wednesday

For example given this date '2010-09-09 00:00:00.000'  This date will have to be dynamic
the query should return
'2010-09-08' and  '2010-09-15'
Related Solutions: Sql 2008 Query weekdays

Answer : Sql 2008 Query

Sorry, Date is your date value.
For example if the date was hardcoded it would look like this.:
select  DATEadd("d",7+4-datepart("dw",'07-31-2010'),'07-31-2010') , DATEadd("d",7-3-datepart("dw",'07-31-2010'),'07-31-2010')

If I wanted it to always be today I would change date to GetDate()
select  DATEadd("d",7+4-datepart("dw",GetDate()),GetDate()) , DATEadd("d",7-3-datepart("dw",GetDate()),GetDate())



Random Solutions  
 
programming4us programming4us