lundi 30 janvier 2017

How to use IF-ELSE statement in a query?

I want to set a date for variable declared within a query depends on a condition. But I couldn't find a working solution for this.
Query

declare @dt datetime;SET @dt ='2010-08-02';set @dt=DATEADD(day,-1,@dt) 
declare @START datetime
declare @END datetime

set @START=(select DATEADD(dd, -(DATEPART(dw, @dt)-2), @dt) [Start])
set @END=(select DATEADD(dd, 8-(DATEPART(dw, @dt)), @dt) [End]);

END
PRINT @START
PRINT  @END 

What I want to do is set date for @START and @END depends on the date of @dt.

Aucun commentaire:

Enregistrer un commentaire