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
A whole flowering branch grafted onto a new limb of an apple tree, the joint wrapped in red tape

Building an Org Chart Query With hierarchyid

April 13, 2012
Pinal Dave
SQL Tips and Tricks
CTE, SQL Datatype, SQL Index, SQL Server

Build an org chart with hierarchyid, query descendants and levels, move a team safely, and compare it with recursive queries.

Read More
A hand lifting a bunch of grapes by its top stem, the branching stems hanging open above a red cloth

Translating Oracle CONNECT BY Queries to Recursive CTEs

February 19, 2012
Pinal Dave
SQL Tips and Tricks
CTE, Oracle, SQL Migration, SQL Server

Translate CONNECT BY into recursive CTEs with root selection, depth, paths, sibling ordering, cycle checks, and a recursion limit.

Read More
A soap bubble floating above a small red bubble wand on a table by a window.

Common Table Expressions Quiz: Why Did My Second Query Fail?

January 27, 2012
Pinal Dave
SQL Puzzle
CTE, SQL Coding Standards, SQL Error Messages

This Common Table Expressions Quiz defines one CTE, reads it once, and then reads it again. The answer is error 208, because a CTE lives for one statement only. A tested script shows the error, the missing semicolon trap and the recursion limit.

Read More
A kitchen sieve with a red rim over a bowl of green lentils, a blank paper tag lying loose beside it.

WHERE Clause Quiz: Why Can’t It See My Column Alias?

January 5, 2012
Pinal Dave
SQL Puzzle
CTE, SQL Column, SQL Error Messages, SQL Order By

This WHERE Clause Quiz asks what happens when a query filters on a column alias. The answer is error 207, because WHERE runs before SELECT. A tested script shows three working fixes and a trap where an alias hides a real column.

Read More
A jigsaw puzzle with pieces sorted into groups before being fitted together

Common Table Expressions for Readability

April 20, 2011
Pinal Dave
SQL Tips and Tricks
CTE, SQL Coding Standards, SQL Server, Temp Table

Common table expressions for readability name query steps and support recursion, but they do not promise cached intermediate results.

Read More
An old spinning wheel taken apart and laid out on a workshop floor in rows from largest part to smallest.

A Bill of Materials With a Recursive CTE

November 8, 2010
Pinal Dave
SQL Tips and Tricks
CTE, SQL Scripts, SQL Server

Expand a bill of materials with a recursive CTE, multiply quantities across levels, trace component paths, and guard against cycles.

Read More
Detailed painting of three matching cup-and-teapot pairs, one on a table, one in a wooden tray, and one on a fixed open shelf.

Derived Table, CTE or View: Choose the Scope

November 10, 2009
Pinal Dave
SQL Tips and Tricks
CTE, SQL Scripts, SQL Server, SQL Sub Query

A derived table, CTE and view can express the same grouped result while offering different scopes. Compare complete outputs with duplicates and NULLs, then choose a statement-local expression or a saved definition for the task.

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

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