Jeff Smith Blog

Random Thoughts & Cartesian Products with Microsoft SQL Server

Criteria on Outer Joined Tables

As this nice SQLTeam article explains, when using an OUTER JOIN, you should put criteria on the outer table in the join condition, not in the WHERE clause. However, I often see a "workaround" to avoid this simple and solid rule, which might seem to work but actually doesn't. Read more →

Hamming Distance Algorithm in SQL

Here's a simple User-Defined Function implementation of the Hamming Distance Algorithm for SQL Server: create function HamDist(@value1 char(8000), @value2 char(8000)) returns int as begin declare @distance int declare @i int declare @len int select @distance = 0, @i =1, @len = case when len(@value1) > len(@value2) then len(@value1) else len(@value2) end if (@value1 is null) or (@value2 is null) return null while (@i <= @len) select @distance = @distance + case when substring(@value1,@i,1) ! Read more →

Have you seen Joe's "Blog" Yet?

I just discovered Joe Celko's weblog; it is really entertaining, at least the 5-6 posts I've read so far! It seems the "blog" is actually just a collection of questions and Celko's rather, umm, "honest" responses from various newsgroups and forums. Read more →

Full Outer Join versus Cross Join

Here is a comparison of a FULL OUTER JOIN and a CROSS JOIN to achieve the same results. See here for more information on this. – Prepare environment:create table A (id int primary key, descr varchar(100))create table seq (seq int primary key)create table B (id int references A(id), seq int references seq(seq), value money, primary key (id,seq))create table C (id int references A(id), seq int references seq(seq), value money, primary key (id,seq))go– Create sample data:insert into Aselect number, 'Name ' + convert(varchar(10), number)from master. Read more →

Full Outer Join versus Union All

(see here for more information on this ) – set it all up: create table A (id int primary key, descr varchar(100))create table B (id int references A(id), seq int, value money, primary key (id,seq))create table C (id int references A(id), seq int, value money, primary key (id,seq))goinsert into Aselect number, 'Name ' + convert(varchar(10), number)from master. Read more →

How to be an Effective Report Writer

Learn the Database Schema Before you can write any reports off of any system, you must be familiar with the schema you are working with. Print out the data dictionary, schema diagrams, documentation -- anything you can find that will help you work with the database. Read more →

Why do only the "Experts" use online help?

Studies have shown that the "F1" key is the least commonly pressed key on today's keyboards! Ok, well maybe not actual studies, but from my own experience, I am convinced that on many keyboards here around the world the F1 key still has that shiny "new key" look and smell because it's never been used. Read more →