Topic: Insert inside Case. Help to solve a problem.

Dear experts, hello!
There is a problem:
On an input the number moves. This number is compared to value range from table 2 and if it is not in the given table, the condition, parity of week, and depending on that is checked, even week or odd, is interposed into table 2 time range.
Actually, my script:

SELECT
CASE WHEN CURRENT_TIMESTAMP NOT Between (SELECT MAX (start) From table2) and (SELECT MAX (finish) From table2)
THEN
CASE WHEN (DATEPART (WEEK, CURRENT_TIMESTAMP) %2) =1
THEN
GO
INSERT INTO table2
(start
,finish)
VALUES
(CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +1, CAST (Current_timestamp as Date)) as datetime)
,DATETIMEFROMPARTS (DATEPART (YEAR, CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +14, CAST (Current_timestamp as Date)) as datetime)), DATEPART (MONTH, CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +14, CAST (Current_timestamp as Date)) as datetime)), DATEPART (day, CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +14, CAST (Current_timestamp as Date)) as datetime)), 23,59,59,000)
GO
ELSE
GO
INSERT INTO table2
(start
,finish)
VALUES
(CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +1, CAST ((Current_timestamp+7)-7 as Date)) as datetime)
,DATETIMEFROMPARTS (DATEPART (YEAR, CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +7, CAST ((Current_timestamp+7) as Date)) as datetime)), DATEPART (MONTH, CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +7, CAST ((Current_timestamp+7) as Date)) as datetime)), DATEPART (day, CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +7, CAST ((Current_timestamp+7) as Date)) as datetime)), 23,59,59,000)
GO
END
END

Actually, the question in what how to force to be fulfilled insert only in one place where the number gets? Why it does at once both ?
Possibly, I understand that put in GO,  how to arrive correctly, yet I will not understand.
Thanks!
The moderator: the Subject is transferred from a forum "MySQL".

Re: Insert inside Case. Help to solve a problem.

pr0b3l1987;

IF (CURRENT_TIMESTAMP NOT Between (SELECT MAX (start) From table2) and (SELECT MAX (finish) From table2))
BEGIN
IF (DATEPART (WEEK, CURRENT_TIMESTAMP) %2) =1
BEGIN
INSERT INTO table2
(start
,finish)
VALUES
(CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +1, CAST (Current_timestamp as Date)) as datetime)
,DATETIMEFROMPARTS (DATEPART (YEAR, CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +14, CAST (Current_timestamp as Date)) as datetime)), DATEPART (MONTH, CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +14, CAST (Current_timestamp as Date)) as datetime)), DATEPART (day, CAST (DATEADD (Day, 1-Datepart (Weekday, Current_timestamp) +14, CAST (Current_timestamp as Date)) as datetime)), 23,59,59,000)
END
ELSE
BEGIN
INSERT INTO table2
(start
,finish)
VALUES
(CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +1, CAST ((Current_timestamp+7)-7 as Date)) as datetime)
,DATETIMEFROMPARTS (DATEPART (YEAR, CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +7, CAST ((Current_timestamp+7) as Date)) as datetime)), DATEPART (MONTH, CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +7, CAST ((Current_timestamp+7) as Date)) as datetime)), DATEPART (day, CAST (DATEADD (Day, 1-Datepart (Weekday, (Current_timestamp+7)) +7, CAST ((Current_timestamp+7) as Date)) as datetime)), 23,59,59,000)
END
END

Re: Insert inside Case. Help to solve a problem.

pr0b3l1987;
1. It is not necessary here GO
2. Take in a habit even if 1 operator, to bracket it begin... end

Re: Insert inside Case. Help to solve a problem.

Mister Uef!;
[quote =] 2. Take in a habit even if 1 operator, to bracket it begin... end

About My God, it where is you such learned?