This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
Gouache painting of calendar cards arranged through the seasons

Formatted Date Alias in ORDER BY: Sort by the Real Date in SQL Server

September 28, 2018
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Order By, SQL Scripts

A formatted date alias can change ORDER BY from a date sort into a text sort. The tests here reproduce the wrong order, show three ways to sort by the real date, and explain the two errors you hit when you try to be clever with the alias.

Read More
Over and partion by query results.

SQL SERVER – Adding Values WITH OVER and PARTITION BY

June 16, 2018
Pinal Dave
SQL Tips and Tricks
Ranking Functions, SQL Function, SQL Order By, SQL Scripts, SQL Server

How do you sum values for each group without GROUP BY and still keep every row? Here is how SUM with OVER and PARTITION BY answers a reader’s question.

Read More
A row of vessels with equal fill heights grouped across a selection boundary

How Does TOP WITH TIES Work in SQL Server? – Interview Question of the Week #159

February 4, 2018
Pinal Dave
SQL Interview Questions and Answers
SQL Function, SQL Order By, SQL Scripts, SQL Server

Question: How Does TOP WITH TIES Work in SQL Server?

Answer: This is an ancient question I just encountered in the recent Comprehensive Database Performance Health Check.

Read More
One red ceramic tile sits first while the remaining tiles follow in a tidy order

How to Keep Certain Records on Top While Ordering Data? – Interview Question of the Week #110

February 19, 2017
Pinal Dave
SQL Interview Questions and Answers
SQL Order By, SQL Scripts, SQL Server

An interview question: how do you keep one city on top while ordering data by name for the rest? The answer is a small trick in the ORDER BY clause.

Read More
The same ceramic buttons are arranged by color in one tray and by size in another

Sort Query Using Dynamic Variables Without EXEC – Interview Question of the Week #074

June 5, 2016
Pinal Dave
SQL Interview Questions and Answers
SQL Order By, SQL Scripts, SQL Server

How do you sort query results by a column passed in a variable? Here is how to sort query output dynamically without EXEC or sp_executesql.

Read More
Aligned asparagus stems entering a mechanical peeler beside crossed stems

BULK INSERT ORDER Hint: Loading Pre-Sorted Files Without a Sort

December 7, 2015
Pinal Dave
SQL Tips and Tricks
Query Hint, SQL Order By, SQL Server

The ORDER hint does not sort anything. It is a promise about your file, and SQL Server checks it. Here is what happens when you break it.

Read More
Collated nail strip with a defined end beside a loose nail heap

The Last Entered Row: Why a Table Needs an Ordering Column

December 27, 2014
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Identity, SQL Order By

A table has no last row until you define one. Here is how identity, event time and ties give different answers.

Read More
Previous 1 2 3 4 5 … 7 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com