|
Posted by Simon Hayes on 09/30/05 01:05
David Portas wrote:
>>create table a
>> (account int
>> ,balance_date datetime
>> ,balance money)
>
>
>
> Why are all your columns nullable? What is/are the key/s of this table?
> Are you aware that MONEY will give you imprecisely rounded results when
> you multiply or divide?
>
> Try:
>
> SELECT account, balance_date, balance
> FROM a AS T
> WHERE balance_date =
> (SELECT MAX(balance_date)
> FROM a
> WHERE account = T.account) ;
>
David,
Are you channelling Celko? :-) Whether or not the columns are NULL or
NOT NULL depends on ANSI_NULL_DFLT_ON/OFF - admittedly, they will be
NULL by default most of the time.
As for money, what data type should an amount of money be; money in
MSSQL is is essentially decimal(19,4), which is a precise data type (and
specifically recommended by BOL for cases where precision is required).
Ignoring the nonsense with currency symbols which MSSQL allows, and
forgetting about currencies like the old Turkish Lira (where dec(24,4)
or more might be needed in certain industries), why would there be any
reason to believe that results will be imprecise?
Simon
Navigation:
[Reply to this message]
|