Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    7

    Unanswered: How make looping in database?

    How to change value to zero if adc0=0. My friend tell me for doing looping.My problem , adc0=0 will display -0.334 at my postgresql database.How to change display to zero?

    10.3 * 0.00001 * new.adc0- 0.334


    Please suggest me the example for looping.Thank you very much.
    That code not work.

    LOOP
    IF adc2=0 THEN new.adc2=0 END IF
    'UPDATE new.adc2 SET new.adc2 = 0 WHERE new.adc2 = 0;
    END LOOP

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Post the structure of your table (DDL)
    Post sample data of the table
    Post expected outcome

  3. #3
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    I don't think you need a loop here. It is not clear exactly what you are trying to accomplish. I can't tell if you want to update the actual values in the db or just change how it is displayed. I'm thinking the latter.

    So to display this you would do this:
    Code:
    SELECT CASE WHEN adc2 = 0 THEN 0
      ELSE 10.3 * 0.00001 * adc0 - 0.334 END AS adc2
    FROM foo

Posting Permissions

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