General information
Forum:
Microsoft SQL Server
Hi Nathani,
Something like this may help you. But i am not sure about the datatypes you want to have in in table B. Change the @myDataType value according to need.
----------
declare @cur_row tinyint, @tot_records tinyint, @sqlstring varchar(1000), @myDataType varchar(50)
select @tot_records = count(*) from Table_A
if @tot_records=0
return
select @cur_row = 2, @myDataType = ' int '
select @sqlstring = 'create table Table_B (myCol1 ' + @myDataType
while @cur_row <= @tot_records
begin
select @sqlstring = @sqlstring + ', myCol'+convert(varchar,@cur_row)+
@myDataType
select @cur_row = @cur_row + 1
end
select @sqlstring = @sqlstring + ')'
exec(@sqlstring)
select * from table_b
-----------
Bye
Raj
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only