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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Display rows into columns
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

200 Posts

Posted - 11/27/2012 :  10:34:39  Show Profile  Reply with Quote
Hello All,

Below result set I need to display in rows as columns.
The result is coming from 3 different replciation servers and I need to compare the record counts between them.

Server Database Table Rows
Srv1 DB1 Tbl1 2000
Srv1 DB1 Tbl2 1000
Srv1 DB2 Tbl1 100
Srv2 DB1 Tbl1 2000
Srv2 DB1 Tbl2 1000
Srv2 DB2 Tbl1 100
Srv3 DB1 Tbl1 2000
Srv3 DB1 Tbl2 1000
Srv3 DB2 Tbl1 100

Result should look like this
Database Table Server1 Rows Server2 Rows Server3 Rows
DB1 Tbl1 Srv1 2000 Srv2 2000 Srv3 2000
DB1 Tbl2 Srv1 1000 Srv2 1000 Srv3 1000
DB2 Tbl1 Srv1 100 Srv2 100 Srv3 100

Can anyone please help with the query?


Elizabeth B. Darcy
Starting Member

United Kingdom
39 Posts

Posted - 11/27/2012 :  11:32:54  Show Profile  Reply with Quote
If you do not need the (in my view the superfluous - it does not add any additional information) Server1,Server2,Server3 columns, you can easily use the PIVOT operator like so
( MAX(ROWS) FOR [Server] IN ([Srv1],[Srv2],[Srv3]) )P

-- Yes, I am indeed a fictional character.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000