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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query trouble

Author  Topic 

jbphoenix
Yak Posting Veteran

68 Posts

Posted - 2011-07-14 : 14:29:25
Basically I'm trying to query a table and only produce 1 row per acctno. Here is what my table looks like.

Port acctno mod modmnth status mnth NoMnths
North 5174 Ext 200708 0 200708 0
North 5174 Ext 200708 15 200709 1
North 5174 Ext 200708 30 200710 2
North 5174 Ext 200708 15 200711 3
North 5174 Ext 200708 30 200712 4
North 5174 Ext 200708 0 200801 5

I would like to have the query to return the port, acctno, mod, modmnth, NoMnths, and status. I need to have the number of months as a column. The data returned should look like this

Port acctno mod modmnth 0 1 2 3 4 5
North 5174 Ext 200708 0 15 30 15 30 0

I tried using pivot I couldn't get it work.

Thanks

   

- Advertisement -