Description:
In this video, I delve into the importance of defensive case expressions in SQL Server queries, particularly focusing on how they can prevent unexpected errors and maintain query reliability. I illustrate this through a practical example where we create a simple table and run a basic percentage calculation query. However, as the transcript highlights, even with straightforward data, issues like division by zero can arise if unexpected values sneak into your database. To address these challenges, I demonstrate how to use case expressions and nullif functions to handle such scenarios gracefully, ensuring that our queries remain robust and error-free. By emphasizing defensive coding practices, we avoid potential disasters, such as ETL processes failing in the middle of the night due to unforeseen errors.
CHAPTERS
00:00:00 - Introduction
00:00:29 - Defensive Case Expressions
00:01:25 - Creating a Table Example
00:01:51 - Unexpected Data Issues
00:02:25 - Implicit Conversion Problems
00:03:18 - Divide by Zero Error
00:03:58 - Using Case Expressions
00:04:35 - Nullif Function Alternative
00:05:30 - Writing Defensively
00:06:25 - Preventing Surprises
━━━━━━━━━━━━━━━━━━━━━━━━━━
???? TRAINING & COURSES
━━━━━━━━━━━━━━━━━━━━━━━━━━
Get AI-Ready With Erik
https://training.erikdarling.com/get-ai-ready-with-erik?coupon=AIREADY
SQL Server Performance Engineering Course
https://training.erikdarling.com/sql-server-performance-engineering?coupon=ENGINEERING
Learn T-SQL with Erik
https://training.erikdarling.com/learn-t-sql-with-erik?coupon=ADVANCEDTSQL
Everything Bundle:
https://training.erikdarling.com/?coupon=SPRINGCLEANING
━━━━━━━━━━━━━━━━━━━━━━━━━━
????️ CONSULTING & SERVICES
━━━━━━━━━━━━━━━━━━━━━━━━━━
Need SQL Server performance help?
https://training.erikdarling.com/sqlconsulting
━━━━━━━━━━━━━━━━━━━━━━━━━━
???? CONNECT
━━━━━━━━━━━━━━━━━━━━━━━━━━
Ask questions at Office Hours
https://erikdarling.com/officehours/
Become a channel member
https://www.youtube.com/@ErikDarlingData/join
━━━━━━━━━━━━━━━━━━━━━━━━━━
Share this link via
Or copy link















































