Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL GO Statement n Times

I have seen many examples and notes where people state you can do the following:

INSERT INTO DatesTable  
   SELECT DateAdd(day, 1, MAX(DatesTable.Dates)) from DatesTable
GO 10

GO n times I hear is a valid way of looping in SQL - but it doesn't work and SQL Server Management Studio doesn't allow it.

Am I doing something wrong or is there a setting I'm not aware of? And if it cannot be done, what is the simplistic alternative.

like image 652
Aaron Gibson Avatar asked Oct 22 '22 09:10

Aaron Gibson


1 Answers

Cheers for confirming its valid people. I found the reason why it didnt want to work - GO simply wants another statement after it so I did a select to see its worked and it allows it all to run - simple and useful.

INSERT INTO DatesTable  SELECT DateAdd(day, 1, MAX(DatesTable.Dates)) from DatesTable
GO 10
SELECT * FROM DatesTable
like image 146
Aaron Gibson Avatar answered Nov 04 '22 01:11

Aaron Gibson