I'm trying to populate my database table with some dummy data and I wrote a loop for that. I'm using DBeaver to connect to my SQL Server db and I run the code against it.
DECLARE @counter INT = 1;
WHILE @counter <= 1000
BEGIN
INSERT INTO dbo.Articles
(ArticleCode, ArticleName)
VALUES
('ARTCODE' + CAST(@counter AS VARCHAR), 'Name' + CAST(@counter AS VARCHAR))
;
SET @counter = @counter + 1;
END;
For some reason, I get an error on line 3 (on the WHILE loop).
SQL Error [137] [S0002]: Must declare the scalar variable "@counter"
What did I do wrong?
;) is a batch separator, not a statement terminator. Have you checked your settings? Are you really attached to DBeaver, or could you change to an IDE that doesn't have the "feature"?