Friday, June 08, 2007

SQL Teaser NULL vs COALESCE

Without running the code, try to guess the output

DECLARE @v1 VARCHAR(3)
DECLARE @i1 INT


SELECT
ISNULL(@i1, 15.00) /2,
COALESCE(@i1 , 15.00) /2,
ISNULL(@v1, 'Teaser #2'),
COALESCE(@v1, 'Teaser #2')

I hope you will use COALESCE instead of ISNULL from now on ;-)

Cross-posted from SQLBlog! - http://www.sqlblog.com/

1 comment:

  1. Thanks for that one. The next time I have to debug a string truncation error and the variable sizes are all properly set, I'll know to search for Coalesce functions :)

    ReplyDelete