How to return default value for NULLs?

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default How to return default value for NULLs?

    Hi,

    I'm doing a left outer join and would like to replace the null values returned for the right table with a default value. Is that possible?

    Blue
    sblue Guest

  2. Similar Questions and Discussions

    1. #39365 [NEW]: getElementsByTagNameNS() does not return elements in a default namespace
      From: z_rules55 at hotmail dot com Operating system: WinXP Professional PHP version: 5.2.0 PHP Bug Type: DOM XML related Bug...
    2. Default Search for 2 field values return all results?
      Hi. I have two fields that users can search for. Either room number or Phone number. They can also put both a room number and a phone number and...
    3. Casting nulls
      IF $int is null and I have a test If($int < 1) { //do some foobar } will $int be evaluated as a zero? IF I cast (int) $int.. will that turn a...
    4. Changing the default elementName for the return value of a Web Method
      Hello Lets say I have a WebMethod with the following Attributes public short method() { return 1; }
    5. Problem with nulls
      I am passing values from a form to an asp page that has the code to update underlying records with all changes. How can I update blank fields that...
  3. #2

    Default Re: How to return default value for NULLs?

    The syntax depends on your database type. Try ..


    SELECT COALESCE(aTextColumn, 'SomeDefaultValue') AS aTextColumn
    SELECT COALESCE(aNumericColumn, 0) AS aNumericColumn
    .......
    mxstu Guest

  4. #3

    Default Re: How to return default value for NULLs?

    Just so that you know ISNULL() will do the same and is ANSI-SQL


    SELECT ISNULL(aTextColumn, 'SomeDefaultValue') AS aTextColumn
    SELECT ISNULL(aNumericColumn, 0) AS aNumericColumn

    SQLMenace Guest

  5. #4

    Default Re: How to return default value for NULLs?

    just to make sure NULL value and '0' value are not the same
    if you want to the data from the table to to have a value of '0' when no
    value is assigned
    you should set the table to have a defaul value of zero instead of NULL it
    will same time and code



    jorgepino Guest

  6. #5

    Default Re: How to return default value for NULLs?

    COALESCE is ANSI SQL!!! (Feature 261-04, as specified by the ANSI/ISO
    SQL-99 and SQL-2003 standards.)

    ISNULL is vendor specific.


    /Jarl

    jarl@mimer.com Guest

  7. #6

    Default Re: How to return default value for NULLs?

    jorgepino, the query is the result of an OUTER JOIN. There are no records in the table that match the query condition; that's why sblue has to handle NULL results.
    philh Guest

  8. #7

    Default Re: How to return default value for NULLs?

    >Just so that you know ISNULL() will do the same and is ANSI-SQL

    SQLMenace,

    Actually I believe it COALESCE() that is ANSI-SQL and ISNULL() is the proprietary function.
    mxstu Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139