Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 ADD columnname type

Author  Topic 

sa
Yak Posting Veteran

77 Posts

Posted - 2007-11-10 : 00:03:02
hi everyone, is it possible to create a table and
an columns dynamically? see below this might
picture what i mean. ('',)

create table mytable (Col0 VARCHAR(20))

declare @Col VARCHAR(5)
declare @i int

set @i = 1
set @Col = 'Col'

while (@i <= 5)
begin
alter table MYTABLE
ADD CONVERT(VARCHAR(10),@COL+@i) int
set @i = @i + 1

end

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-10 : 01:43:24
Yes, it is possible (not practical), but why dynamic SQL?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-10 : 03:50:59
what do you want to do actually ? Maybe there is a better way of doing it.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -