I saw that, but it does not work for my application.
I need to create a adaptive insert statements transferring data in one table to a table on a different server. SSIS is not allowed.
In order to do this, I need to access the data in the table via the column ID of the columns.
This is how I get the column Names
declare @count INT, @columncount int, @dataOut varchar(8000), @tablename varchar(200)
select @tablename = 'Patient'
select @columncount = COUNT(*) from Sys.columns where OBJECT_ID = OBJECT_ID(@TableName)
select @count = 1
select @dataOut = ''
while @count < @columncount + 1
Begin
select @dataout = @dataout + (Select NAME from sys.columns WHERE OBJECT_ID = OBJECT_ID(@TableName) and column_id = @count)+','
Select @count = @count +1
Continue
End
select @dataOut
Now I need to pair the actual data from the row to the columns
This is for a adpatively generated Insert statement