round function for specific criteria 
Author Message
 round function for specific criteria

Hi,

I have a table with the following data,  and use a view to format
information.  I have been asked to round a certain field to either 2
or 4 places, depending on another field value....

Table
Name        ID        Price
Fred          12        101.11001
John          11        58.432
Peter          12       223.98119
Martin         5         12.001

View
SELECT distinct
"field1" = Name,
"field2" = ID,
"field3" = Price
FROM
tablename

Can anyone point me in the right direction of how to check if ID = 12
and then round to either 2 or 4 decimal places ?

Martin



Sat, 06 Nov 2004 22:19:20 GMT
 round function for specific criteria


Quote:
> Hi,

> I have a table with the following data,  and use a view to format
> information.  I have been asked to round a certain field to either 2
> or 4 places, depending on another field value....

> Table
> Name        ID        Price
> Fred          12        101.11001
> John          11        58.432
> Peter          12       223.98119
> Martin         5         12.001

> View
> SELECT distinct
> "field1" = Name,
> "field2" = ID,
> "field3" = Price
> FROM
> tablename

> Can anyone point me in the right direction of how to check if ID =
12
> and then round to either 2 or 4 decimal places ?

> Martin

Use the 'case' expression:

select case ID when 12 then round(price, 2) else round(price, 4)
from your_table

HTH,

Rob
----------------------------------------------------------------------
Rob Verschoor

Certified Sybase Professional DBA for ASE 12.0/11.5/11.0

Author of "The Complete Sybase ASE Quick Reference Guide"
Online orders accepted at http://www.sypron.nl/qr


WWW  http://www.sypron.nl
snail Sypron B.V., P.O.Box 10695, 2501HR Den Haag, The Netherlands
----------------------------------------------------------------------



Sat, 06 Nov 2004 22:32:14 GMT
 round function for specific criteria

Quote:
> Use the 'case' expression:

> select case ID when 12 then round(price, 2) else round(price, 4)
> from your_table

Correction: I forgot the 'end' keyword in the above query. It should
be:

select case ID when 12 then round(price, 2) else round(price, 4) end
from your_table

HTH,

Rob V.



Sat, 06 Nov 2004 22:58:10 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. FileMaker Pro - Search for specific criteria

2. send specific oracle 8i table data to specific sql server 2000 table at specific times

3. Access Functions as ADP Query Criterion ?

4. Convert function for varchar criteria.

5. Using VB Functions in Query Criteria

6. Rounding error, SQL Server functions

7. Round Functions

8. About Round Function

9. Round Function

10. Round Function

11. Round Function

12. MOd and Round Function


 
Powered by phpBB® Forum Software