I have the following query where in a temporary table I keep every Monday between a range of dates.
DECLARE @TEMP TABLE(REGISTRO DATE)
DECLARE @startdate datetime = '2017-01-19'
DECLARE @enddate datetime = '2017-02-19' ;with cte(col)
AS
(
SELECT @startdate
UNION ALL
SELECT col + 1
FROM cte
WHERE col <= @enddate
)
INSERT INTO @TEMP
SELECT *
FROM cte
WHERE DATEDIFF(dd,2,col)% 7 = 0
I get a table with the results:
2017-01-25
2017-02-01
2017-02-08
2017-02-15
Now in a real table in my database I need to create a record for each result obtained in this case it would be INSERT for the visit table
INSERT INTO Visita (fecha) VALUES('2017-01-25')
INSERT INTO Visita (fecha) VALUES('2017-02-01')
INSERT INTO Visita (fecha) VALUES('2017-02-08')
INSERT INTO Visita (fecha) VALUES('2017-02-15')