I have written a query to create a table having dynamic columnsDeclare @cols varchar(2000)Declare @query varchar(2000)Select @cols = COALESCE(@cols + ',['+[header]+'] varchar(10)','['+[header]+'] varchar(10)' from ColumnHeadersTable) SET @query = 'DECLARE @tempTable TABLE( ID uniqueidentifier, '+@cols+')'EXECUTE(@query)
Though this query executes successfully,After this if i refer the @tempTable i get error sayingMust declare the table variable "@tempTable".Any ideas whats happening here ??RegardsSrivatsa