According to a temporary table (Table Schema and data) -
according temporary table (table schema , data), how can create physical table , insert returned records it?
hi,
in below sample code , retriving columns temp table using case condition..
in step 2 checking column has been selected case statement.. in step 3 selecting columns have been retrieved above case stmnt.. in step 4 creating physical table columns names have selected above , inserting it.. atlast drop both tables
i hope you
step1:
declare @dynsql nvarchar(max) select @dynsql = case when columnname1 >0 ',columnname' else '' end + case when columnname2 >0 ',columnname2' else '' end + . . case when columnnamen >0 ',columnnamen ' else '' end ##temptble condition = cond;
step 2:
if(len(@dynsql) > 0) begin
step 3:
set @dynsql = stuff(@dynsql,1,1,'select machinename, ') + ' ##temptble' exec(@dynsql) end decalre f nvarchar(max)
step 4:
set @f = stuff(@dyncreate,1,6,'create table ven_temp( descriptionname nvarchar(111),' ) + ' int )' exec(@f) insert ven_temp exec(@dynsql)
Comments
Post a Comment