Results 1 to 2 of 2

Thread: select statement

  1. #1
    Join Date
    Aug 2004
    Posts
    14

    Unhappy select statement

    Hi

    I have an accounts package which uses a sql database and one table within this database holds the orders table.
    I am trying to run a simple report which works out the total value of the orders - the table holds in seperate columns the following data - value, quantity and spare - now normally I would do a sum(quantity*val) to get my total per row however if the customer uses a foreign currency the exchange rate is held in the spare field.
    therefore I do sum(quantity*sum/spare) this works fine where there is a rate but when it is blank I get the error cannot divide by zero

    Any ideas what I am doing wrong or a workaround?

    Thanks for any help!
    Sagsh

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can use ISNULL function to divide by 1 if the column value is NULL.

    sum(quantity*sum/ISNULL(spare,1))

Posting Permissions

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