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 2000 Forums
 Transact-SQL (2000)
 Transpose query(columns to rows)

Author  Topic 

sameerv
Starting Member

29 Posts

Posted - 2003-11-13 : 10:06:44
I have a table with the following structure:

ID numeric
TransactionType char(1){Credit/Debit}
Amount numeric

The rows in the table are:
ID TransactionType Amount
1          C              100
2          D              50
3          D              200
4          C              75

I need a single Query to create a view whose output will be:
ID Credit Debit

1     100     Null
2     Null     50
3     Null     200
4     75      Null

nic
Posting Yak Master

209 Posts

Posted - 2003-11-13 : 11:13:44
try this

SELECT
ID
,(CASE WHEN TransactionType = 'C' THEN Amount ELSE Null END) AS Credit
,(CASE WHEN TransactionType = 'D' THEN Amount ELSE Null END) AS Debit
FROM
table


Nic
Go to Top of Page
   

- Advertisement -