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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE WHEN NULL

Status
Not open for further replies.

CBear

Instructor
Jun 1, 2001
21
0
0
CA

Hey,

Anyone know the proper construct for SQL Server stored procedure where you want to trap null in a case statement

eg.
Select
Case EMPLOYEE.Name
when NULL then ''
when '' then ''
else EMPLOYEE.Name END as EmployeeName
From
EMPLOYEE


Thanks,
 
Code:
select case when Employee.Name is null then 
      ''
   else 
      Employee.Name 
   end as EmployeeName
from Employee

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(Not quite so old any more.)
 
Can't you just use ISNULL(yourcolumn,'') AS YOURFIELD?
 
Yeah, it is :) I was agreeing with your construct as simpler than Case, giving a similar example.

Question, does COALESCE do exactly the same thing as ISNULL?
 
coalesce(a,937) is the same as isnull(a,937)

however, the equivalent of coalesce(a,b,c,937) is a little trickier to write with isnulls :)

r937.com | rudy.ca
 
... and uglier as well:

isnull(isnull(isnull(a, b), c), 937)

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top