CASE statement or UDF?

  • So I've got a legacy database..

    There are a number of INT columns in it which may have values of -32768 which is supposed to represent a NULL value.

    I need to return these -32768's as actual NULL's in a T-SQL query (updating the data in the DB is not an option).

    Currently the query is like so:

    SELECT

    CASE WHEN col1 = -32768 THEN NULL

    ELSE col1 END

    FROM tbl1

    My question is, would I get a performance benefit by creating a UDF to filter out the -32768 values and using it like so:

    SELECT

    myUdf(col1)

    FROM tbl1

    ?

  • There is NULLIF system function for your service.

    See BOL for details.

    _____________
    Code for TallyGenerator

  • Ah - thanks.

  • HI,

    use case in your update query.It is better rather to create a function because you can't use the update statement in your functions

     

    Regards

    Amit

     

     

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply