Results 1 to 3 of 3

Thread: NZ function in SQL Server = COALESCE()?

  1. #1
    Join Date
    Mar 2005
    Posts
    3

    NZ function in SQL Server = COALESCE()?

    I'm a missing something or is the script "NZ function in SQL Server" just a two-parm version of the built-in COALESCE function?

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048
    NZ is closer to the IsNull() function in T-SQL than to Coalesce(). IsNull() is a two parameter function.

    Coalesce is a multiple parameter version of the IsNull function. You can give it any amount of options, and it returns the first one that isn't null (or null if all parameters are null).

    The main differnece between NZ and the SQL Server equivalents is that IsNull() and Coalesce() both require that the values be the same data type or at least convertable to each other's data types.

    For example, this will give you an error in T-SQL because a string can not be converted to an integer:

    Select IsNull('A String', 0)


    MAK posted a user defined function for SQL Server that exactly mimics the functionality of NZ somewhere.

  3. #3
    Join Date
    Dec 2004
    Posts
    502
    Here is MAK's function:

    NZ function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •