Add dated records to MSSQL using while loop


/ Published in: SQL
Save to your folder(s)

This loop adds a bunch of records to your database with a date field pre-populated. Works well for pre-populating a table for filling out daily by a form


Copy this code and paste it in your HTML
  1. DECLARE @imax INT,
  2. @i INT
  3. SET @imax = 400 -- change to max value
  4. SET @i = 1
  5.  
  6. while (@i <= @imax)
  7. BEGIN
  8. INSERT INTO Workflow_status
  9. (WF_date)VALUES (CONVERT(DATE, getdate() + @i,101))
  10. SET @i = @i + 1
  11.  
  12. END

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.