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
 General SQL Server Forums
 New to SQL Server Programming
 How to add values based on row

Author  Topic 

pushp82
Yak Posting Veteran

83 Posts

Posted - 2012-01-17 : 05:23:24
Hi Friends,

I have a table (CTE output) as
Date MobileNo orderno amount
Jan 6 2012 La9tit870 2 1318.32
Jan 06 2012 9311808518 1 448.32
Jan 06 2012 9820257071 1 870
Jan 9 2012 La9tit870 1 576.96
Jan 09 2012 9897080841 1 576.96

I need to sum the values for each date for other than MobileNo 'La9tit870' (This is static value).

OutPut:

Date orderno amount Source
Jan 6 2012 2 1318.32 La9tit870
Jan 6 2012 2 1318.32 Others

I'm in dark please show me a taurch........ASAP please

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-17 : 07:16:11
[code]select
Date,
sum(amount) as Amount,
'Others' as Source
from
yourTable
where
MobileNo <> 'La9tit870'
group by
Date,
MobileNo
UNION ALL
select
Date,
Amount,
MobileNo
from
YourTable
where
MobileNo = 'La9tit870'[/code]
Go to Top of Page

pushp82
Yak Posting Veteran

83 Posts

Posted - 2012-01-18 : 01:26:50
quote:
Originally posted by sunitabeck

select
Date,
sum(amount) as Amount,
'Others' as Source
from
yourTable
where
MobileNo <> 'La9tit870'
group by
Date,
MobileNo
UNION ALL
select
Date,
Amount,
MobileNo
from
YourTable
where
MobileNo = 'La9tit870'




Thank you sunita this worked for me...
Go to Top of Page
   

- Advertisement -