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 merge data

Author  Topic 

immad
Posting Yak Master

230 Posts

Posted - 2014-12-30 : 06:47:34
HI,
I have a problem.
my data is look like this.

EvS_VoucherCode--------Name----TotalAmount
ACT----------------------------1------------------3
ACT----------------------------1------------------3
DEF----------------------------2------------------4
DEF----------------------------2------------------4
DEF----------------------------2------------------4

i want data looks like this.

EvS_VoucherCode--------Name---------TotalAmount
ACT-------------------------------2-----------------6
DEF-------------------------------6------------------12

please help me out.
thanks for the help.

immad uddin ahmed

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-12-30 : 07:29:34
[code]
CREATE TABLE #temp(EvS_VoucherCode varchar(100),Name int,TotalAmount int)
INSERT INTO #temp
SELECT 'ACT',1,3 UNION ALL
SELECT 'ACT',1,3 UNION ALL
SELECT 'DEF',2,4 UNION ALL
SELECT 'DEF',2,4 UNION ALL
SELECT 'DEF',2,4

SELECT EvS_VoucherCode,
SUM(Name),
SUM(TotalAmount)
FROM dbo.#temp
GROUP BY EvS_VoucherCode

DROP TABLE dbo.#temp

[/code]

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -