Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

egemen_ates
Yak Posting Veteran

Turkey
76 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

3873 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
76 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

3873 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  
 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.22 seconds. Powered By: Snitz Forums 2000