Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select Statement Column Subqueries
Message
 
 
À
16/10/2005 22:37:35
Czarina Joyce Villanueva
Innovision Systems International
Manila, Philippines
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01059532
Message ID:
01059535
Vues:
15
This message has been marked as the solution to the initial question of the thread.
Select custno,
	SUM(CASE WHEN trantype = 1 THEN amount ELSE 0 END) AS debit,
	SUM(CASE WHEN trantype = 2 THEN amount ELSE 0 END) AS credit
  from tranledger 
  GROUP BY custno
>
>Using SQLServer 2000, I have a table called tranledger with columns amount, trantype, custno. I want to create a select statement wherein I could be able to separate amount as debit and amount as credit where trantype = 1 and 2 respectively. So instead of having 2 select statement to get the desired output, I want to have one select only. Would it be possible?
>
>
>Select amount as debit from tranledger Where trantype = 1
>Select amount as credit from tranledger where trantype = 2
>
>How can I have a single select statement based on the 2 statements above?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform