Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to create tables dynamically using while loop and insert the records from another table.

$
0
0


Hi,
i need how to create tables dynamically using while loop.

this below query is created for one table but i need dynamically.


declare @columns nvarchar(max)
set @columns='['+'MemberID'+'] Mem_ID,'+  '['+'RefID'+'] int,'
select @columns =  @columns+
                  '['+COALESCE( replace(conditionname,'_sys_defined',''),' ,')+'] datetime,'
                  from Condition
where GrpID=23
select @columns='create table Dise_23('+SUBSTRING(@columns, 1, LEN(@columns) - 1)+')'
exec sp_executeSql @columns

how to change this query for dynamic table creation using while loop.

here create the dynamic table is based on GrpID.

please modify this query...


Regards,
Abdul Khadir.M


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>