Case Statement Foiled By Null

Case Statement Foiled By Null

This article applies to Microsoft SQL server. The concept of null can be confusing to programmers and non-coders alike. For databases, the normal understanding as defined by ANSI is null means anything or nothing. It’s literally an undefined value. As such,...
T-SQL Divide-By-Zero

T-SQL Divide-By-Zero

Divide-by-zero errors are one of the first errors new programmers come across. A reasonable fix is to check the denominator and, if it equals zero, provide some useful result as an alternative to running the division operation. In a table you must think in sets of...
How to Pull Record Counts for Tables

How to Pull Record Counts for Tables

One way to familiarize one’s self with a very non-production database is to get a list of tables and record counts for each. Table name and count iterator Transact-SQL declare @tbl nvarchar(400); -- internally generated, table name declare @sch nvarchar(400); --...