Converting Double To Numeric In Sybase IQ

Today a person development team has asked me to make a dump of a table to a file in csv format. The problem comes with double data types need to convert them to numeric, here is a problem that must convert each type column double to type numeric with the convert function. No chance to do something generic, like it could be a “SET OPTION”.

An example of the convert function Sybase we can see below;

 
SELECT 
COL1 AS "FLOAT POINT",
CONVERT( numeric(19), str_replace(str(COL1,19),',','.')) AS "WITHOUT DECIMALS",
CONVERT( numeric(19,2), str_replace(str(COL2,19,2),',','.')) AS "WITH TWO DECIMALS"
FROM 
MY_TABLE_OF_TESTCASES

We get the next result ;

 
FLOAT POINT            WITHOUT DECIMALS      WITH TWO DECIMALS     
---------------------- --------------------- --------------------- 
1.0227126E7            10227126              10227126,00           
1.0227625E7            10227625              10227625,00           
1.0227674E7            10227674              10227674,00           

HTH – Antonio NAVARRO

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s