Nobody seems to ask questions about SQL Expressions in forums, even though expressions can cause all sorts of problems. It's time for some straight-forward Q&As, and who better than Robert Sheldon to give the A?
Read more...

There times when you need to write T-SQL code that creates specific T-SQL Code and executes it. When you do this you are creating dynamic T-SQL code. When writing dynamic T-SQL you need to understand how dynamic code opens the possibilities for a SQL injection attack.
Read more...

A lot of numbers that we use everyday such as Bank Card numbers, Identification numbers, and ISBN codes, have check digits. As part of the routine data cleansing of such codes we must check that the code is valid- but do we? Dwain Camps shows how it can be done in SQL in such a way that it could even be used in a constraint, and keep bad data out of the database.
Read more...

When you are writing TSQL code there are times when you want to perform the same logic over and over again. To accomplish this you can used the WHILE keyword. There are other times when you want to perform a conditional test and depending on the results of the test you execute one code block for the TRUE condition and possibly a different code block when the condition is FALSE. When you need to conditionally execute code based on the outcome of a condition you can used the IF keyword. In this Stairway level I will be discussing how to use the WHILE and IF constructs to control the flow of your TSQL code.
Read more...

It's a well known fact that Scalar UDFs are the stuff of performance nightmares in T-SQL. But are they really as bad as they say? SQL Server MVP Jeff Moden shows us that they might not really be as big a problem as you might think and what you can do when they actually are.
Read more...

Joe Celko finds a reference to Conway's Game of Life while clearing out his desk, and is suddenly gripped with nostalgia. It wasn't just flares, mullets and disco, but simple computer games in interpreted basic. Somehow, Conway's Game of Life was too intriguing to be abandoned in the attic. Can it be implemented in SQL? Joe sets up a challenge.
Read more...

SQL Server User-Defined Functions are good to use in most circumstances, but there just a few questions that rarely get asked on the forums. It's a shame, because the answers to them tend to clear up some ingrained misconceptions about functions that can lead to problems, particularly with locking and performance
Read more...

Cursors are considered by many to be the bane of good T-SQL. What are the best ways to avoid iterative T-SQL and to write queries that look and perform beautifully? In the next part of an ongoing series, we look at ways to efficiently retrieve recently modified data.
Read more...

Cursors are considered by many to be the bane of good T-SQL. What are the best ways to avoid iterative T-SQL and to write queries that look and perform beautifully? This first part in an ongoing series of cursor-killing handles inter-row analysis.
Read more...