I have been trying for days to find a way to refer to table field names in TSQL
I have a table CFlowDefs which is simply 200 smalldatetime fields named DT_1 to DT_200
I have a loop which is intended to insert incremental dates into each of the required fields starting from DT_1, then DT_2 etc as far as needed (defined by @NumDays). All I want to do is be able to refer to the required field in CFlowDefs that needs updating using a string (@NextField )
set @counter = 2
while @counter < @NumDays +2
begin
set @StrCounter = CAST(@counter as varchar)
set @NextField = 'DT_' + @StrCounter <-- String to create next field name
set @NextDate = dateadd(d,1,@NextDate)
update CFlowDefs
set @NextField = @NextDate --<---- HELP !!!
set @counter = @counter + 1
end
any help would be very much appreciated
I have a table CFlowDefs which is simply 200 smalldatetime fields named DT_1 to DT_200
I have a loop which is intended to insert incremental dates into each of the required fields starting from DT_1, then DT_2 etc as far as needed (defined by @NumDays). All I want to do is be able to refer to the required field in CFlowDefs that needs updating using a string (@NextField )
set @counter = 2
while @counter < @NumDays +2
begin
set @StrCounter = CAST(@counter as varchar)
set @NextField = 'DT_' + @StrCounter <-- String to create next field name
set @NextDate = dateadd(d,1,@NextDate)
update CFlowDefs
set @NextField = @NextDate --<---- HELP !!!
set @counter = @counter + 1
end
any help would be very much appreciated