Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
If you consider a to be the same as b when they are both NULL, then the solution is a little more complicated. Here’s one way:
WHERE a = b
OR (a IS NULL AND b IS NULL);
Also, don’t the rules change if the item is a string ?
You’ll to do something extra if your definition of “the same” does not correspond to the system’s definition of “=”. (The example of NULLs, above, is a special case of this.)
If a and b are strings, and you want to distinguish between capital and small letters, but the system doesn’t (that is, if considers capital ‘B’ to be equal to small ‘b’), then you have to convert the strings to some other type where the difference in case does matter to the system. In SQL Server, you might say:
WHERE CAST (a AS VARBINARY (10)) =
CAST (b AS VARBINARY (10));
There may be some system somewhere that considers (e.g.) ‘B’ stroed in a 10-character fixed-length column to be different that the same letter ‘B’ stored in a 20-character fixed-length column. In that case, you might have to explicitly convert the shorter one to the longer type, or do a separate test for length.