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

Case select on tiny int but return null as blank char not zero 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I seem unable to get the syntax right to use a case select on a tinyint column that returns blank if it is null.

I have
Code:
CAST(
Case When
(Final_Rating IS NULL)
Then ''
Else Final_Rating
End AS Char(1))

But the returned result for those that are NULL show ZERO not blank?

How do I return blank for a tinyint column that is NULL?

Thanks,

Craig.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Craig,
The problem you're having is that the conditional is being resolved by the bit state of the non-NULL result. Move the "Cast" to solve:
Code:
Case When
(Final_Rating IS NULL)
Then ''
Else CAST(Final_Rating
AS Char(1)) 
End
Now each result is a string.
HTH,
lex


soi là, soi carré
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top