Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rows as column 1

Status
Not open for further replies.

password99

Technical User
Jul 19, 2002
122
US
i need to display row data as columns:

Un DB it is stored as :

Cash 100
Check 200
Credit Card 300
Other 400
Cash 500
Check 600


I need to display it as:

Cash Check Credit Card Other
600 800 300 400




How can I do that?
 
Code:
SELECT
  SUM(CASE WHEN type = 'cash' THEN value ELSE 0 END) AS cash,
  SUM(CASE WHEN type = 'check' THEN value ELSE 0 END) AS check,
  SUM(CASE WHEN type = 'credit card' THEN value ELSE 0 END) AS creditcard,
  SUM(CASE WHEN type = 'other' THEN value ELSE 0 END) AS other
FROM t1

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top