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 four nested bowls on a kitchen counter with the smallest center bowl painted red

Order of Operations in SQL Server: How PEMDAS Works in T-SQL

September 25, 2012
Pinal Dave
SQL Tips and Tricks
Mathematics, SQL Operator, SQL Scripts, SQL Server

The order of operations in SQL Server follows PEMDAS, so 6/2*(1+2) returns 9. This post walks through the precedence rules with tested queries. It also covers integer division, the negative number trap and AND before OR.

Read More
Two shoes sit immediately on opposite sides of a narrow doorway threshold strip

DATEDIFF Counts Boundaries, Not Time: Getting Durations Right

July 10, 2012
Pinal Dave
SQL Tips and Tricks
Mathematics, SQL DateTime, SQL Function, SQL NULL

A report can say one year of service after a single day. Here is why DATEDIFF does that, and what to use instead.

Read More
A ski boot buckle stays on the same adjustment tooth despite a small pull on its strap

The real Data Type: Seven Digits of Precision and Overflow

June 30, 2011
Pinal Dave
SQL Tips and Tricks
Mathematics, SQL Data Storage, SQL Datatype, SQL Error Messages

Four bytes look like a bargain until a total comes out wrong. Watch real round, overflow and drift, then decide when decimal is the safer pick.

Read More
Two similar wooden tops, one upright and one leaning on its rim with an off-center tip.

Comparing Float Values: Why 0.1 + 0.2 Is Not 0.3 in SQL Server

December 5, 2008
Pinal Dave
SQL Tips and Tricks
Best Practices, Mathematics, SQL Datatype, SQL Scripts

Why does 0.1 + 0.2 miss 0.3 only when float is involved? A few tiny queries show the hidden digits, the drifting sum and two clean fixes.

Read More
Four small pipettes rest in white cups while a hand drips amber liquid from a fifth pipette into a glass blending bottle.

Weighted Scores: Ranking Products by Several Columns at Once

February 10, 2008
Pinal Dave
SQL Tips and Tricks
Mathematics, Ranking Functions, SQL Order By, Temp Table

Adding rating to units sold ranks by whichever column is biggest. Scale first, weigh second, and keep the weights in a table anyone can read.

Read More
Previous 1 2
  • Books
  • Testimonials
  • Privacy Policy

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