I am trying to set individual columns of a table variable iteratively as follows:
declare @reg_data table
(
I int NOT NULL PRIMARY KEY IDENTITY,
Y float
)
declare @counter int, @numRows int
SET @counter = 0
SET @numRows = (select MAX(val) + 10 from tableY)
WHILE @counter < numRows
BEGIN
SET @reg_data.Y = dbo.func1(@counter) --HOW DO I DO THIS!!!
@counter = @counter + 1
END
The above does not work because you cannot access table variables like an array. How can I obtain the following functionality?
You can’t set values in records that doesn’t exists, so you need an
insert: