Case Statement Replacement for performance

I've a data in the table which has 0 value for certain number of columns; but, the requirement is to display NULL if 0, I've many such columns and converting like this is causing performance issue, I've to do it at the db end only in the SP which returns the data

with the below statement it is working fine but, at the stake of performance.  do you've any better replacement or idea for this.

I've used 

CASE [Col1] WHEN 0 THEN NULL ELSE [Col1] END AS [ColumnFirst],

July 30th, 2015 5:23pm

Take a look at NULLIF function in BOL.

NULLIF(Col1, 0) as Col

But basically, it's the same thing and should not affect the performance if these columns are used in the select stat

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 5:26pm

Hi Naomi,

I am looking for NULLs if actual value is 0

July 30th, 2015 6:01pm

That is what NULLIF does
Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 6:20pm

Hi Naomi,

I am looking for NULLs if actual valu

July 30th, 2015 6:24pm

Exactly what Jason said and what I meant - if you're not using these fields in where or join, then it doesn't matter how you write the columns in the SELECT part of the query - using CASE, IIF or NULLIF - there should be no performance problems related with that.
Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 6:34pm

CASE is an expression, not astatement. Is that misconception why you think that  this would be a performance problem? CASE is part of a family with  COALESCE() and NULLIF() that use the same underlying compilations. 
July 30th, 2015 9:03pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics