there is no output, because you keep changing @NOW, but not @Today. that means you never go into the IF @Today=@Day unless GETUTCDATE() returns a monday. i guessed that since you keep iterating @NOW which yields @Today, you would like to keep @Today on @NOW's weekday.
i took the liberty of adding the update to @Today to your code:
DECLARE @Day varchar(20);
DECLARE @Today varchar(20);
DECLARE @StartDate datetime;
DECLARE @EndDate datetime;
DECLARE @NOW datetime;
SET @NOW=GETUTCDATE();
SET @Today=CONVERT(varchar(20),(select datename(dw,@NOW)))
SET @Day='Monday';
DECLARE @intFlag INT
SET @intFlag = 0
WHILE (@intFlag <7)
BEGIN
IF @Today=@Day
BEGIN
SET @StartDate=DATEADD(day,-6,@NOW);
SET @EndDate=DATEADD(day,0,@NOW);
PRINT @StartDate;
BREAK;
END
SET @NOW=DATEADD(day,1,@NOW);
SET @Today=CONVERT(varchar(20),(select datename(dw,@NOW)))
SET @intFlag = @intFlag + 1
END
EDIT
after reading your commentary, here is some more code. I chose a past tuesday for reference (01.01.1980) so that monday will be a the 0 in the case construct. i know this is not ideal, but try it anyways:
declare @Day varchar(20);
declare @pastweekday datetime;
set @Day = 'Monday';
set @pastweekday = dateadd(day, case when @Day = 'Monday' then 0
when @Day = 'Tuesday' then 1
when @Day = 'Wednesday' then 2
when @Day = 'Thursday' then 3
when @Day = 'Friday' then 4
when @Day = 'Saturday' then 5
when @Day = 'Sunday' then 6
end
, '19800101')
SELECT DATEADD(day, (DATEDIFF (day, @pastweekday, GETUTCDATE()) / 7) * 7, @pastweekday)