Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Windowing Ranges Expand / Collapse
Author
Message
Posted Monday, December 9, 2013 7:17 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 6:30 AM
Points: 1,803, Visits: 2,167
Mighty (12/9/2013)
Maybe worthwhile to mention that this functionality was introduced in SQL Server 2012.


Yes! Had a heck of a time figuring it out, UNTIL I realized it must be something new for 2012. Then all became clear.

Thanks for the question.


Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Post #1521079
Posted Monday, December 9, 2013 10:01 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: 2 days ago @ 8:55 PM
Points: 4,421, Visits: 3,414
Straightforward and nice - thanks, Steve!
Post #1521203
Posted Monday, December 9, 2013 11:31 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 4:24 PM
Points: 3,289, Visits: 1,969
Nice question Steve! I wish we would upgrade to 2012 around here so we could use these new functions.

Good stuff.

Ken
Post #1521250
Posted Monday, December 9, 2013 12:43 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 8:01 AM
Points: 332, Visits: 1,051
Any examples of how these would be used?
Post #1521271
Posted Monday, December 9, 2013 12:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:36 PM
Points: 6,593, Visits: 8,874
KWymore (12/9/2013)
Nice question Steve! I wish we would upgrade to 2012 around here so we could use these new functions.

Good stuff.

Ken


The upgrades to the OVER clause alone are, IMHO, worth the upgrade.


Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #1521272
Posted Monday, December 9, 2013 2:18 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:58 PM
Points: 5,965, Visits: 8,216
marcia.j.wilson (12/9/2013)
Any examples of how these would be used?

Running totals. Traditionally done with slow set-based code, with a (relatively!) fast cursor, or with some dangerous unsupported side effect of a language feature.

In SQL Server 2012, very simple:

SELECT   SalesPersonName,
SaleDate,
Amount,
SUM(Amount) OVER (PARTITION BY SalesPersonName
ORDER BY SaleDate
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal
FROM YourTable
ORDER BY SalesPersonName, SaleDate;




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #1521306
Posted Monday, December 9, 2013 9:10 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 8:01 AM
Points: 332, Visits: 1,051
Hugo Kornelis (12/9/2013)
marcia.j.wilson (12/9/2013)
Any examples of how these would be used?

Running totals. Traditionally done with slow set-based code, with a (relatively!) fast cursor, or with some dangerous unsupported side effect of a language feature.

In SQL Server 2012, very simple:

SELECT   SalesPersonName,
SaleDate,
Amount,
SUM(Amount) OVER (PARTITION BY SalesPersonName
ORDER BY SaleDate
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal
FROM YourTable
ORDER BY SalesPersonName, SaleDate;



Thanks. That helped me get a better picture of why you would use this.
Post #1521385
Posted Monday, December 9, 2013 10:59 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 4:53 PM
Points: 21,617, Visits: 15,271
WayneS (12/9/2013)
KWymore (12/9/2013)
Nice question Steve! I wish we would upgrade to 2012 around here so we could use these new functions.

Good stuff.

Ken


The upgrades to the OVER clause alone are, IMHO, worth the upgrade.


+1




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1521400
Posted Tuesday, December 10, 2013 5:47 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 1:53 PM
Points: 4,130, Visits: 3,157
Love the access to other rows in the set. Still waiting for 2012. Sigh.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1521473
Posted Tuesday, December 10, 2013 12:03 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 4:24 PM
Points: 3,289, Visits: 1,969
Ed Wagner (12/10/2013)
Love the access to other rows in the set. Still waiting for 2012. Sigh.


I was doing some BI work in QlikView a couple years ago and they had some great built-in analytic functions for lead, lag, percent_rank and a few others. Saved me a bunch of coding. Since that application did everything in memory, access to other rows in the set was a built in feature. Very handy.

Supposedly upgrading to 2012 next year. We shall see...
Post #1521630
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse