Advertisement

06.27.2008 at 08:26AM PDT, ID: 23521963
[x]
Attachment Details

convert rows into columns

Asked by xtremereality in MS SQL Server, SQL Server 2005

Tags: T-SQL

HI all,
I need to convert some rows into a columns.

hi have this query:
SELECT    
            dbo.tblWebCasts.uWebCastID as WebcastID,
            dbo.tblWebCasts.sTitle as Title,
            isnull(dbo.tblWebCasts.iStartDate, 0) as StartDate,
            isnull(dbo.tblWebCasts.iEndDate, 0) as EndDate,
            dbo.tblStatus.sStatus as Status,
            isnull(dbo.tblFormat.sFormatIcon, '') as FormatIcon,
            isnull(dbo.tblWebcastTypes.sType, '') as Template
FROM        
            dbo.tblWebCasts INNER JOIN
            dbo.tblStatus ON dbo.tblWebCasts.uStatusID = dbo.tblStatus.uStatusID INNER JOIN
            dbo.tblWebcastTypes ON dbo.tblWebCasts.uTypeID = dbo.tblWebcastTypes.uTypeID INNER JOIN
            dbo.tblWebcastFormats ON dbo.tblWebCasts.uWebCastID = dbo.tblWebcastFormats.uWebCastID INNER JOIN
            dbo.tblFormat ON dbo.tblWebcastFormats.uFormatID = dbo.tblFormat.uFormatID

that produce this table

WebcastID                   Title                   StartDate                   EndDate                    Status                   FormatIcon                   Template
1                                 title1                    20080623                 20080624                 true                       icon/icon1.jpg                template1
1                                 title1                    20080623                 20080624                 true                       icon/icon2.jpg                template1
1                                 title1                    20080623                 20080624                 true                       icon/icon3.jpg                template1
2                                 title2                    20080623                 20080624                 true                       icon/icon1.jpg                template4

What I need is convert the 3 rows (for istance the first 3 rows for webcastID 1) into columns.
Something like

WebcastID        Title       StartDate        EndDate       Status       FormatIcon               FormatIcon2       FormatIcon3 ......
1                        title1       20080623      20080624     true         icon /icon1.jpg          icon/icon2.jpg       <--- from webcast ID1 f. ex.

Any suggestion?Start Free Trial
[+][-]06.27.2008 at 08:51AM PDT, ID: 21885016

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Server 2005
Tags: T-SQL
Sign Up Now!
Solution Provided By: aneeshattingal
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628