I have N1 table where columns name(id,Field). Base on the fields of this table I want to create N2 table from SP where data from N1 will be columns in N2. id Field -- ------ 1 ID 2 First 3 Last
========================================== Cursors are useful if you don't know sql. DTS can be used in a similar way. Beer is not cold and it isn't fizzy.
I solve the problem. Check it out DECLARE @SQL varchar (8000) DECLARE @Field varchar (8000) set @SQL='Create table N2(' DECLARE Field CURSOR FOR select '['+netid+'] varchar(50)'+ --Insert coma after each record and remove from the last one-- (case when netid=(select distinct Top 1 netid from N1 order by ID desc) then '' else ',' end) from N1 order by ID OPEN Field FETCH NEXT FROM Field INTO @Field WHILE @@FETCH_STATUS = 0 BEGIN SELECT @SQL= @SQL + @Field FETCH NEXT FROM Field INTO @Field END SELECT @SQL = @SQL +' )' CLOSE Field DEALLOCATE Field
Only any good if you want all varchar(50) columns which would be very unusual.
========================================== Cursors are useful if you don't know sql. DTS can be used in a similar way. Beer is not cold and it isn't fizzy.