Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Friday Teaser NULL vs COALESCE

Status
Not open for further replies.

SQLDenis

Programmer
Joined
Oct 1, 2005
Messages
5,575
Location
US
Without running the code, try to guess the output
Code:
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 ;-)



Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com
Google Interview Questions
 
Here is my guess.

7
7.50
fail
Tea

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Almost!

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
I would not have known had I not run into this problem before.

7
7.5
Tea
Teaser #2

Ignorance of certain subjects is a great part of wisdom
 
Hmmmm, my try:

can't make Null into type decimal
divide by 0 error
Teaser #2
Can't convert type varchar to type int




[monkey][snake] <.
 
That is why I try to convince people to get in the habbit of always using COALESCE. That and ASNSI compliance. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top