Re: select query

From: Vishal Parkar (REMOVE_THIS_vgparkar_at_yahoo.co.in)
Date: 12/01/04


Date: Thu, 2 Dec 2004 01:26:48 +0530

see following example. replace actual column / table names with yours.

try:

create table t (acct int, dramt int, cramt int)
go
insert into t values (101,5, null)
insert into t values (103,5, null)
insert into t values (101,null, 10)
go
select acct, case when amt > 0 then amt else 0 end dr_amt,
case when amt < 0 then abs(amt) else 0 end cr_amt
from
(select acct, sum(isnull(dramt,0)) - sum(isnull(cramt,0)) amt from t group
by acct) x
go

-- 
Vishal Parkar
vgparkar@yahoo.co.in | vgparkar@hotmail.com


Relevant Pages