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 line of stepping stones across a pond with the last one vermilion

Generate a Date Range: List All Dates Between Two Dates

January 13, 2021
Pinal Dave
SQL Tips and Tricks
CTE, SQL DateTime, SQL Scripts, SQL Server

To generate a date range in SQL Server, number the days between a start date and an end date and add each number to the start. This post shows a recursive CTE, its limit of 100 recursions, GENERATE_SERIES, a version for older servers, and how to handle times and missing days.

Read More
SQL SERVER - CTE can be Updated

SQL SERVER – CTE can be Updated

May 19, 2014
Pinal Dave
SQL Tips and Tricks
CTE, SQL Scripts, SQL View

Users often confuse a CTE with a temp table, but a CTE works like a view, and a CTE can be updated just like one. Matthew Spieth’s tip, with my notes.

Read More
A potato ricer above regular portions and a smaller final remainder

Loan Amortization Schedules With a Recursive CTE

April 16, 2014
Pinal Dave
SQL Tips and Tricks
CTE, Mathematics, SQL Datatype

Why does the last loan payment leave a few cents behind? A recursive CTE, a rounding rule and a final reconciliation fix it.

Read More
Execution plan for SQL server query.

SQL SERVER – Does Use of CTE Change the Order of Join in Inner Join

March 24, 2014
Pinal Dave
SQL Tips and Tricks
CTE, Execution Plan, SQL Joins

A reader said he uses a CTE to control join order. Does a CTE change the order of join in an inner join? Here is what I found.

Read More
A bulb planter beside separate clusters of shoots and empty planting hollows

Cohort Retention Tables in T-SQL: From Raw Events to a Grid

October 6, 2013
Pinal Dave
SQL Tips and Tricks
Business Intelligence, CTE, SQL DateTime, SQL Group By

Build a retention grid from raw orders with five rows you can check by eye. Includes the DISTINCT rule and why unfinished months show NULL.

Read More
A hand lifts the top glass from a pyramid of stacked glasses, a red napkin at its base.

Walking Foreign Key Chains to Find a Safe Delete Order

November 3, 2012
Pinal Dave
SQL Tips and Tricks
CTE, SQL Constraint and Keys, SQL Delete, SQL Server

Map foreign key chains from a parent table with a recursive catalog query, then list deepest children first and flag cascade rules.

Read More
Five lesson rows with their results: error 2627 caught and thrown again, a procedure that returned 11,200.00 while a direct SELECT failed with 229, tea found on slips 1 and 3, the breadcrumb Library > Garden > Herbs > Basil, and a hint that cut reads from 5,740 to 318

SQL Server Lessons: Five Short Scripts You Can Run in a Minute

May 16, 2012
Pinal Dave
SQL Tips and Tricks
CTE, Query Hint, SQL Server Security, SQL XML

SQL Server lessons stick when you can run them in a minute. This page covers errors, security, XML, hierarchies and query hints. Each lesson asks one question and answers it with a short script. Every result comes from SQL Server 2025.

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

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