Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
T-SQL Data Analysis with Stored Procedures: Advanced
New
1 students

T-SQL Data Analysis with Stored Procedures: Advanced

Window frames, dynamic SQL, indexes, MERGE and incremental loads in SQL Server, with a bank cost-to-serve project
Last updated 11/2026
English
English

What you'll learn

  • Control window frames with ROWS and RANGE, and calculate moving averages, quartiles, medians and percentiles
  • Solve gaps-and-islands problems to find dormant accounts and activity streaks
  • Generate date spines and build a calendar table with recursive CTEs
  • Write safe dynamic SQL with sp_executesql and QUOTENAME, and build a dynamic pivot procedure
  • Measure and tune queries with STATISTICS IO, execution plans, indexes and SARGable conditions
  • Keep tables in sync with MERGE, incremental watermark loads and table-valued parameters
  • Build a cost-to-serve model that reallocates support costs to branches on drivers

Course content

7 sections • 25 lectures • 2h 55m total length
  • Welcome to the advanced course4:03
  • Set up, and the format functions17:18
  • Section 1 quiz

Requirements

  • Comfortable with SELECT, JOIN, GROUP BY, CTEs, window functions and stored procedures (the intermediate course, or equivalent)
  • SQL Server 2017 or later (the free Developer or Express edition is fine) and SQL Server Management Studio
  • A Windows PC, or SQL Server in Docker on Mac or Linux

Description

This course contains the use of artificial intelligence.

You already write CTEs, window functions and stored procedures. This course takes you to the next level: the techniques database professionals use to build fast, safe and reliable analytics in SQL Server, with every technique written inside a stored procedure that anyone can run again with one line.

You'll work with Protea Bank, a fictional South African bank with 12 branches, 600 customers, 1,457 accounts and 60,000 transactions. Every query is run on screen in SQL Server Management Studio, with real results, and every script is included so your results match the lectures exactly. Every lecture starts with a topic and a question, there's a comment above every line of code, and you see each new procedure, index and table type appear in Object Explorer, with every new table opened while it's empty, then again after it's filled. Every result is formatted so it's easy to read: money in rand with thousands separators, counts with separators, and percentages, while calculations and sorting run on the real numbers.

What you'll learn

  • Advanced window functions: ROWS versus RANGE frames, moving averages, year-to-date totals, NTILE quartiles, medians with PERCENTILE_CONT, and the classic gaps-and-islands problem.
  • Recursive CTEs: number sequences, date spines that show the days when nothing happened, and a South African calendar table with weekends and public holidays.
  • Subtotals: ROLLUP, CUBE and GROUPING SETS, and the ISNULL truncation trap.
  • PIVOT and dynamic SQL: cross-tab reports, UNPIVOT, sp_executesql, a live SQL injection demonstration and how to prevent it, QUOTENAME, and a dynamic pivot procedure whose columns follow the dates you ask for, and are formatted on the fly.
  • Query performance: logical reads with STATISTICS IO, execution plans, clustered and nonclustered indexes, covering indexes with INCLUDE, and SARGable conditions. You'll cut reads from 454 to 24 on screen.
  • Loading data: MERGE with OUTPUT, incremental loads with a watermark inside a transaction, checked against the source, and table-valued parameters.
  • Project: a cost-to-serve model that reallocates support cost centres (HR, IT, facilities, operations and risk) to branches on headcount, transactions and accounts, then calculates the cost per account and per transaction.

Each section ends with a practice lecture and a quiz, and there's a quiz on the setup too. The course includes 10 practice exercises with full answers, a script for every lecture, and the database setup script.

The narration voice is AI-generated. All names, account numbers and figures are fictional.

Who this course is for:

  • Data analysts who want to write faster, safer and more professional T-SQL
  • Finance, banking and management accounting professionals who work with SQL Server
  • Report developers who build Excel and Power BI reports on SQL Server
  • Students of the beginner and intermediate T-SQL courses who are ready for the next step