Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2004, 03:21 AM
Registered User
 
Join Date: Jan 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select query problem

Dear all
I had a table which contain :

customer id,
charge type,
charge amount.

how i can create a select query which will show the amount of charge depend on different 'charge type', each type will show in individual column, so the result table will look something like this :

Cusotmer id Penalty Charge Penalty Interest
012625 150 20
216050 300 05

thx alot

Jack

 
Old January 19th, 2004, 07:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You need a query like this to generate your required output - if you have other charge types, you'll need to add a further SUM(CASE...) for each one.
Code:
SELECT [customer id], 
    SUM(CASE [charge type] WHEN 'charge' THEN [charge amount] ELSE 0 END) AS [Penalty Charge],
    SUM(CASE [charge type] WHEN 'interest' THEN [charge amount] ELSE 0 END) AS [Penalty Interest]
FROM <<YourTable>>
GROUP BY [customer id]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Query Problem akhilesh_g SQL Server 2000 2 December 18th, 2007 04:59 AM
SELECT from SELECT query? seananderson Access 1 October 12th, 2007 12:40 AM
Need help on select query arul1984 SQL Server 2000 2 July 4th, 2007 01:49 AM
Select Query Help dbartelt Access 1 June 13th, 2005 08:06 AM
Select Query String Problem phungleon SQL Server 2000 8 June 9th, 2004 05:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.