masri999
3/21/2007 6:08:00 PM
On Mar 21, 9:24 pm, NH <N...@discussions.microsoft.com> wrote:
> I am writing some dynamic sql and I need to 'pivot' a column of field names
> from the syscolumns table;
>
> I need to convert this:
>
> name
> FIELD1
> FIELD2
> FIELD3
> FIELD4
>
> To this:
>
> 'FIELD1,FIELD2,FIELD3,FIELD4'
>
> I can do it fairly easily with VBS but before I do, is there a simple way of
> doing it within SQL?
>
> Thanks
>
> NH
in SQL 2005 , if in SQL 200 use syscolumns table
select
max(case when column_id = 1 then name end) as field1,
max(case when column_id = 2 then name end) as field2,
max(case when column_id = 3 then name end) as field3,
max(case when column_id = 4 then name end) as field4
from sys.columns
where object_id = 4