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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 No Repeat

Author  Topic 

kjk_kjp
Starting Member

18 Posts

Posted - 2011-02-28 : 10:37:26
Morning,
I have a query that returns the following data:

ID SEC R_COST C_COST
1 ab 60 275
2 ab 60 275
3 ab 60 275
2 xy 45 275
4 xy 45 275
5 xy 45 275

What I need the query to return is the following:

ID SEC R_COST C_COST
1 ab 60 275
2 ab 60 0
3 ab 60 0
2 xy 45 275
4 xy 45 0
5 xy 45 0

Basically I'm only wanting to see/calc the C_COST once per SEC.

Any thoughts?

Thanks!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-28 : 10:42:51
you can make use of row_number() over (partition by SEC order by ID) in your query. Return C_COST value when row_number() returns 1


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kjk_kjp
Starting Member

18 Posts

Posted - 2011-02-28 : 10:44:10
Good Idea, I will play round with the RowNumber and see if I can get it to work for my needs.

Thanks for the idea.
Go to Top of Page

kjk_kjp
Starting Member

18 Posts

Posted - 2011-02-28 : 10:56:14
The RowNumber worked - thanks again!
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-28 : 11:08:29
you are welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -