Results 1 to 3 of 3

Thread: An SQL String Question

  1. #1

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    An SQL String Question

    This is more of a general SQL question rather than specific PHP but I couldn't find a better section to post it on!

    Is there a way of doing an SQL statement that says "Replace any field in this row with a 0 if that field is a null"?
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, since there could be fields (like VARCHAR or BLOB) that don't accept 0 as value. In one query you could set every field to 0 (or something similar) if the field you check for in the row is null.
    But you could use more than one query like
    UPDATE tablename fieldname='0' WHERE fieldname=NULL
    UPDATE tablename otherfield='0' WHERE otherfield=NULL


    But don't rely on what I've said, I've never got deep into obscure SQL commands.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Maybe a better answer could be generated if you told us why you need to do something like this?

    Surely setting a default would make their no need for a code approach, if that's what your problem is.

    Maybe you could explain?
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width