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: under a market awning two wicker baskets of apricots stand apart

HAVING Without GROUP BY: Filter One Implicit Aggregate Group

June 10, 2008
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

HAVING without GROUP BY filters the single implicit aggregate group produced by the query. I use that distinction when a summary should appear only if its aggregate condition passes. A false condition can remove the summary row entirely.

Read More
Gouache painting: on a vineyard floor four small wooden grape tubs sit in a two by two block, red and white grapes from two vineyard blocks

CUBE: Include Every Two-Dimensional Subtotal Combination

March 3, 2008
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

CUBE requests every grouping combination of its dimensions, including independent subtotals and the grand total. I compare its output population with ROLLUP before choosing it. More subtotal families are useful only when the report needs them.

Read More
Three upright carved wooden forms stand in a shallow wooden tray beside a red cloth and tool case.

REPLICATE: Zero Copies and Negative Counts Differ

January 27, 2008
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

REPLICATE treats zero copies differently from a negative count. I keep the source and requested count beside the result. Byte lengths and NULL flags reveal several blank-looking outcomes.

Read More
Two ivory trays hold separate groups of small blue and cream ceramic dishes.

Conditional COUNT: ELSE 0 Counts Nonmatching Rows

January 13, 2008
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

Conditional COUNT includes zero when CASE returns it. I compare an omitted ELSE with a zero branch before aggregating. A no-match group and an empty input expose the difference from SUM.

Read More
Gouache painting: on three barn shelves stand jars of honey from one harvest

GROUPING SETS: Choose Nonhierarchical Subtotals Explicitly

December 30, 2007
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

GROUPING SETS lets me choose independent subtotal combinations instead of assuming one hierarchy. I list the groups the report needs explicitly. That can exclude detail rows while retaining summaries across different dimensions.

Read More
Two small terracotta bowls and one large pale bowl holding blue pebbles, with one vermilion pebble in the large bowl.

GROUPING_ID: Separate Stored NULL Values From ROLLUP Totals

August 26, 2007
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

GROUPING_ID helps me distinguish a stored NULL from a subtotal created by ROLLUP. Both can appear in the same column. I keep the grouping bits beside the numbers before adding presentation labels.

Read More
Two rows of blue and pale ceramic beads on wooden guides, with one terracotta bead.

WINDOW: Reuse an Explicit Running-Total Frame

February 28, 2007
Pinal Dave
SQL Tips and Tricks
SQL Function, SQL Reports, SQL Scripts, SQL Server

WINDOW lets me name a window definition and reuse it across compatible calculations. I still specify the partition, ordering and frame. A short name should make the intended calculation easier to review.

Read More
Previous 1 … 6 7 8 9
  • Books
  • Testimonials
  • Privacy Policy

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