SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Conditionally Order By Different Column

By Noel Scheaffer,

I came across a situation yesterday that I don’t remember encountering before so I figured it would be worth sharing. The objective was to get the top 5 Card Numbers for each BIN based on the absolute value of either the CreditAmount or DebitAmount. I figured I needed to use a CASE statement which I have done plenty of times, but never quite like this.

Total article views: 431 | Views in the last 30 days: 21