I need to insert a certain number of rows into a SQL Server table.
DECLARE @val AS INT = 20, @val2 AS VARCHAR(50), @Date AS DATETIME = CONVERT(DATETIME,'02-05-2016'), @i AS INT = 0 SET @val2 = 'abc' DECLARE @tbl TABLE ( [ID] [int] IDENTITY(1,1) NOT NULL, [val2] VARCHAR(50) NULL, [datum] [datetime] NULL )
In this query, I need to insert the dates, starting from the given date, to the number of the value assigned to the variable "@val". Thus, in this case, 20 rows must be inserted into the table, starting from '02 -05-2016 ', and then increasing the number by 1 day for each row.
How can I do this in a single expression without any loops or multiple insert statements?
sql-server sql-server-2008
Hemant Sisodia Sep 20 '16 at 13:35 2016-09-20 13:35
source share