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 a shelf of preserve jars with one empty jar and a bare gap holding a vermilion ribbon

Convert Empty String to NULL Date in SQL Server: Use NULLIF

May 6, 2021
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL NULL, SQL Scripts

To convert empty string to NULL in a date column, wrap the text in NULLIF before you cast it. A plain CAST returns 1900-01-01 and hides the problem. This post tests five expressions on six text values, including a real 1900 date, a run of spaces and a tab, and shows which ones stay correct.

Read More
Gouache painting of three potted seedlings on a greenhouse shelf, the middle one in a deep vermilion pot and slightly taller, with a wooden ruler leaning at the front

Simple Interest in SQL Server: A Function That Keeps Cents

April 30, 2021
Pinal Dave
SQL Tips and Tricks
SQL Datatype, SQL Function, SQL Scripts, SQL Server

Simple interest in SQL Server is principal times rate times years divided by 100, and a T-SQL function returns it in one line. This post shows how an int return type drops the cents and what SCHEMABINDING changes. It measures the cost of a scalar function on 500,000 rows and ends with compound interest.

Read More
Gouache painting of two identical windows showing the same garden at night, with a small potted plant between them

AT TIME ZONE Twice: Convert UTC to Local Time in SQL Server

February 22, 2021
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts, SQL Server

AT TIME ZONE twice converts UTC to local time in SQL Server. The first use labels a plain value as UTC and the second converts it. A demo shows the common one step mistake, stores in three cities, and the missing and repeated hours of daylight saving.

Read More
A tall stack of pancakes on one plate and a fresh plate with a single pancake, a hand adding the next one.

Running Totals That Reset Every Month

February 5, 2021
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts, SQL Server

Calculate running totals that reset by calendar month, customer, or fiscal period, using stable ordering and explicit ROWS frames.

Read More
Leeks trimmed at both ends on a chopping board, roots and tough tops in two small piles.

LTRIM and RTRIM With Custom Characters in SQL Server 2022

January 26, 2021
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Server, SQL Server 2022, SQL String

Use LTRIM and RTRIM with custom characters in SQL Server 2022, understand character sets, test TRIM directions, and preserve valid text.

Read More
Sixteen pineapples in a row by size, split into four groups by wooden slats, one huge pineapple set apart.

Quartiles With PERCENTILE_CONT and NTILE

January 1, 2021
Pinal Dave
SQL Tips and Tricks
Mathematical Function, Ranking Functions, SQL Function, SQL Server

Compare quartiles from PERCENTILE_CONT with NTILE row buckets, calculate interquartile range, and flag candidates beyond 1.5 IQR.

Read More
Gouache painting of a strand of wooden beads above three small rings of beads, the middle ring holding one vermilion bead

Convert Integer to Date in SQL Server: ddMMyyyy Values

December 9, 2020
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts

To convert integer to date values such as 09122020, split the number into day, month and year and build the date from the parts. This post compares four methods on tested data, shows why a lost leading zero and the session language break two of them, and times them on a million rows.

Read More
Previous 1 … 3 4 5 6 7 8 9 … 92 Next
  • Books
  • Testimonials
  • Privacy Policy

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