Retrieving zero dollar from MDB

  • Thread starter Thread starter T Jones
  • Start date Start date
T

T Jones

Hi,

My MDB contains price and price1. If it is zero dollars, MDB shows
$0.00. From VB, how do I display all records that are $0.00? Each price and
price1 field is Currency. Using VB6.

strSQL = "SELECT * FROM Products WHERE price = " ???

Thanks.
 
Hi,

My MDB contains price and price1. If it is zero dollars, MDB shows
$0.00. From VB, how do I display all records that are $0.00? Each price and
price1 field is Currency. Using VB6.

strSQL = "SELECT * FROM Products WHERE price = " ???

Thanks.

strSQL = "SELECT * FROM Products WHERE price = 0;"

Currency types are in simplest terms formated numbers.
 
strSQL = "SELECT * FROM Products WHERE price = 0;"

Some 'best practice' asides:

1) Never use SELECT * in production code.

2) Be consistent as regards data types, decimal scale, etc e.g. (air
code)

CREATE TABLE Products (
product_name VARCHAR(20) NOT NULL UNIQUE,
price CURRENCY DEFAULT 0.0000 NOT NULL
)
;
SELECT product_name, price
FROM Products
WHERE price = CCUR(0.0000)
;

It may make you think about whether you need exactly four decimal
places.

3) Use a SQL PROCEDURE to which strongly-typed parameter values may be
passed e.g.

CREATE PROCEDURE GetProductsByPrice (
arg_price CURRENCY = 0.0000
)
AS
SELECT product_name, price
FROM Products
WHERE price = arg_price
;
Currencytypes are in simplest terms formated numbers.

I think "formatted numbers" may be an oxymoron <g> but I agree
CURRENCY does have implications for 'formatting' that may or may not
be appropriate for the purposes to which it is put (for me a
'currency' column means the ISO 4217 three letter codes e.g. 'USD').
The most basic point is that CURRENCY is a fixed point *exact* decimal
numeric type (DECIMAL is the other more flexible one), as distinct
from the floating point *approximate* numeric types (Single, Double)
which are most inappropriate for money data.

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top