SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

egemen_ates
Yak Posting Veteran

Turkey
74 Posts

Posted - 09/27/2013 :  03:49:42  Show Profile  Reply with Quote
How can i write this query ?

TABLE

CODE AMOUNT
100 20
100.01 10
100.01.10 7

OUTPUT

CODE AMOUNT
100 37
100.01 17
100.01.10 7

Thanks for answers

James K
Flowing Fount of Yak Knowledge

3334 Posts

Posted - 09/27/2013 :  08:27:18  Show Profile  Reply with Quote
select
	code,
	sum(amount) over(order by len(code) desc) as Amount
from
	yourTable;
Go to Top of Page

egemen_ates
Yak Posting Veteran

Turkey
74 Posts

Posted - 09/27/2013 :  11:33:07  Show Profile  Reply with Quote
quote:
Originally posted by James K

select
	code,
	sum(amount) over(order by len(code) desc) as Amount
from
	yourTable;





Thanks for answer but im not using your query this table.how can i write this query another way ?

TABLE

CODE AMOUNT
100 20
100.01 10
100.01.10 7
200 10
200.01 6

OUTPUT

CODE AMOUNT
100 37
100.01 17
100.01.10 7
200 16
200.01 6
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3334 Posts

Posted - 09/27/2013 :  11:43:09  Show Profile  Reply with Quote
select
	code,
	sum(amount) over(partition by LEFT(code,3) order by len(code) desc) as Amount
from
	yourTable;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000