I have a table (single column) with about 20 records. In a stored proc
i want to take each of these records and use them as the column name
for a new table.
This has to be a dynamic solution as the number of rows in the first
table is subject to change.
Can anyone guide me on the syntax i need to do this,
Thx, Mark
--
- Anith
(Please respond only to newsgroups)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hope it helps some.
declare @SQL varchar(2000), @Row varchar(200), @FieldType varchar(30)
set @FieldType = 'varchar(100)'
set @SQL = 'Create Table ''Bob'' ('
create cursor mycursor for select fieldname from table
open mycurs
fetch next from mycursor into @Row
while @@fetchstatus = 0
begin
set @SQL = @SQL + ', '+@Row + @FieldType
fetch next from mycursor into @Row
end
close mycursor
deallocate mycursor
set @SQL = @SQL +')'
exec(@SQL)
Anyone help with the dynamic column thing??
http://www.sqlmag.com/Articles/Index.cfm?ArticleID=15608
-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.
"Mark Cooper" <ma...@liquidjelly.co.uk> wrote in message news:4ffdebd9.03031...@posting.google.com...