Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 4 of 4 total |
String Formats in SQL when CASTing |
Mon, Aug 17 2009 8:18 AM | Permanent Link |
"Hedley Muscroft" | Is there any way to control the formatting when CASTing to a string?
Here's how to reproduce my situation :- [1] create table test ( datetime timestamp, amt numeric(0,2) ); [2] insert into test values (timestamp '2009-08-01 10:00:00', 20); [3] select 'Bob paid ' || cast(amt as varchar(30)) || ' on ' || cast(datetime as varchar(20)) from test The result is as follows :- Bob paid 20 on 2009-8-1 10:00 Primarily, I would like to format the '20' as '20.00'. If possible, I would also like to be able to format the date/time but I suspect EDB will format it based on the current locale? The following works correctly in PGSQL by forcing the output to 2 decimal places :- select 'Bob paid ' || cast(cast(amt as numeric(0,2)) as varchar(30)) || ' on ' || cast(datetime as varchar(20)) from test However the output remains the same in EDB even with the extra CAST. Any ideas please? |
Mon, Aug 17 2009 9:11 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Hedley
Unless Tim comes up with a magic bullet the only suggestion I can make is to write your own custom function to do the formatting Roy Lambert [Team Elevate] |
Mon, Aug 17 2009 10:18 AM | Permanent Link |
Uli Becker | Hedley,
here a function I use to format a date into the German order: FUNCTION "FormatDate" (IN "InDate" DATE) RETURNS VARCHAR(10) COLLATE ANSI BEGIN RETURN CAST(EXTRACT(DAY FROM InDate) as VARCHAR(2)) + '.' + CAST(EXTRACT(MONTH FROM InDate) as VARCHAR(2)) + '.' + CAST(EXTRACT(YEAR FROM InDate) as VARCHAR(4)); END Uli |
Wed, Aug 19 2009 4:06 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Hedley,
<< Is there any way to control the formatting when CASTing to a string? >> This is on the list of enhancements and should be available within a month or so. It will be an extension with the keyword FORMAT and will most likely use the same formatting as the import/export in terms of dates/times/numbers/booleans. << The following works correctly in PGSQL by forcing the output to 2 decimal places :- >> Hmm, that's a bit weird. -- Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Tuesday, May 7, 2024 at 02:40 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |