October 13, 2015 at 11:46 pm
some remarks
1. V11 (Azure) don't support OVER (ORDER BY) in Aggretates
2. the NEXT VALUE with OVER is interesting things to play
I'd like to persist current rank over order by some attribute. Unfortunately OVER isn't supported in UPDATE and MERGE. But there is workoround
-- use NOrthwind -- :)
-- /*
create sequence nr as int start with 1
-- */ alter sequence nr restart with 1
go
alter table products add x int
go
update products
set x = t.n
from products p
join (select productid, next value for nr over (order by unitprice) n from products) T
on p.productid = t.productid
go
select * from products
go
alter table products drop column x
drop sequence nr
with bests
Henn
October 14, 2015 at 12:00 am
Comments posted to this topic are about the item Understanding the OVER Clause in SQL Server
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 14, 2015 at 12:10 am
James and Cynthia must be some pretty epic DBA's @ $3000\hr 🙂
Nice article. thank you.
October 14, 2015 at 12:31 am
October 14, 2015 at 5:54 am
Excellent article - thank you.
October 14, 2015 at 7:01 am
Excellent Article! Thanks for posting this. We always find a way to query what we need.
This will allow ( for me at least ) to be a bit more surgical. I use row_number() frequently but
was unaware of all the other uses for OVER as well as ROWS & RANGE. Moving forward, I know this will cut down on the lines of code needed... replacing sub queries or CTE's I'd previously use to get different aggregate values.
Thanks again,
Bob.
October 14, 2015 at 7:02 am
Fantastic article.. thanks
October 14, 2015 at 7:58 am
Great article.
October 14, 2015 at 8:17 am
Thanks for taking the time to write this. Took me way beyond what I've done with the OVER function.
October 14, 2015 at 8:26 am
Is there any stairway about analytics functions?
October 14, 2015 at 12:34 pm
Thanks so much for the article. I learned a lot.
- Les
October 14, 2015 at 1:26 pm
Thanks for this clear and concise article, it really helps. I especially appreciated the inclusion of examples of WHY you would use each combination.
October 14, 2015 at 2:43 pm
My turn to "stalk", ol' friend. 😀 Very well done!
--Jeff Moden
Change is inevitable... Change for the better is not.
October 14, 2015 at 5:54 pm
Henn,
I'm afraid that I just don't understand why you're going through the effort to create a sequence, just to have an incrementing number. Why not just use the ROW_NUMBER function?
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 14, 2015 at 5:57 pm
Thanks to all for the kind words of appreciation for this article - it makes it all worthwhile. I'm glad that it has been so well received, and even more glad that you are learning from it.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 15 posts - 1 through 15 (of 23 total)
You must be logged in to reply to this topic. Login to reply