I have a query like below and it generate a temporary table automatically based on parameter. So, the number of column of this table can be vary. Now , i need to add an auto incremental id column into this table.How i do it?
SELECT @SourceFields INTO ##StoreSourceInfo FROM testdb.dbo.@SourceTable
Note: 1) Number of source field & name of table pass using the parameter @SourceFields & @SourceTable.
2) So, the number of column can be vary on ##StoreSourceInfo table.
Current Result:
select * from ##StoreSourceInfo shows only the available column.
Expected Result:
select * from ##StoreSourceInfo query will show an additional auto incremental id column & all rest of the column available in the temp table.
Hope you get me. Thanks in advance.
Use the identity function. See the link for an example. http://msdn.microsoft.com/en-us/library/ms189838.aspx