Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32

    Question Unanswered: a select with null

    it is possible in a SELECT sentence enforce a NULL value?

  2. #2
    Join Date
    May 2002
    Posts
    27
    what do you mean enforce a null value?

  3. #3
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32
    For exemple in SQLServer I can do this:
    SELECT field1, NULL, field2 FROM table1
    Similary I can enforce some value, for exemple:
    SELECT field1, 7, field2 FROM table1

  4. #4
    Join Date
    May 2002
    Posts
    27
    yes... for the case of the nulls you can do this

    SELECT field1, '', field2 FROM table1

    use to single quotes (''),
    and for the 7 enclose it with single quotes.

    SELECT field1, '7', field2 FROM table1

    did i get to solve your problem?

  5. #5
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32
    not exactly, because I want make a UNION:
    SELECT field1, '' FROM table1
    UNION
    SELECT field1, field2 FROM table2

    If field2 from table2 is a numeric value, teh UNION fails
    In addition '' is a blank value, not a null value.

    Otherwise I will think an alternative way to solve my problem.
    tanks

  6. #6
    Join Date
    Nov 2001
    Location
    Finland, Kirkkonummi
    Posts
    17
    Originally posted by daboira
    not exactly, because I want make a UNION:
    SELECT field1, '' FROM table1
    UNION
    SELECT field1, field2 FROM table2

    If field2 from table2 is a numeric value, teh UNION fails
    In addition '' is a blank value, not a null value.

    Otherwise I will think an alternative way to solve my problem.
    tanks
    SELECT field1, NULLIF(1,1) FROM table1
    UNION
    SELECT field1, field2 FROM table2

    That NULLIF must be cast into correct datatype and lenght. Only integer seems to work automatically.
    If field2 were a VARCHAR(50) then the clause would be

    SELECT field1, CAST(NULLIF(''1'',''1'') AS VARCHAR(50))
    FROM table1
    UNION
    SELECT field1, field2 FROM table2


    Hopefully this helps.

    Vesku

  7. #7
    Join Date
    May 2002
    Posts
    1
    Hi, try to use this in your select:

    char ( nullif( 1 , 1 )) as firstname2,
    date( nullif( 1 , 1 )) as date_of_birth2,
    integer ( nullif( 1 , 1 )) as person_id2,

    I hope this is what you wanted.

    CU Hannes

  8. #8
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32
    ok, with the function nullif all is right

Posting Permissions

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