Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    126

    Unanswered: If Else question URGENT

    I want to run a query that will insert rows into another table.

    I also want to do some calculations on a couple of the columns:


    SELECT
    KEYCODESTRINGDESCRIPTION,
    STRING,
    Mailed,
    Sales,
    Orders,
    CATALOGTITLE,
    Response = Orders / Mailed,
    [Average Invoice] = Sales / Orders,
    SMP = (Sales / Mailed) * 1000

    INTO TP_GA_REPORT
    FROM TP_GA_REPORT_TEMP

    I have a condition where some of the colums might have a 0 in them, which of course causes a "Divide by 0" error. What I would like to do is put an IF statement in the query to deal with this 0.

    i.e.

    if orders = 0 then response=0
    else response = Response = Orders / Mailed

    Hope this makes sense!

    Thanks Ken

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: If Else question URGENT

    Try using SQL CASE:

    SELECT ...,
    CASE WHEN Mailed = 0 THEN 0 ELSE Orders / Mailed END,
    ...
    FROM ...

  3. #3
    Join Date
    Jan 2003
    Posts
    126
    Thank you!!! So very much, worked like a charm!

Posting Permissions

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