Solved

string manipulation in informix tsql

Posted on 2008-06-11
4
1,627 Views
Last Modified: 2013-12-24
Hello experts,

I have trouble using my TSQL knowledge to create queries on Informix Databases. I want to do a daily grouping. I have a column with whole date time expression including time information. In TSQL, I use a left(datetime,10) grouping and it works just fine. I cant do it with Informix.

2008-05-30 18:39:11.705
2008-06-04 15:33:04.267
2008-06-05 13:16:10.912
2008-06-05 14:40:50.751
2008-06-05 14:51:45.001
2008-06-05 19:00:33.626
2008-06-06 10:29:12.463

What can I do to achieve this? What can I do to replace the 'Left' method?

Thank you in advance
0
Comment
Question by:bozer
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:TheLastStraw
ID: 21768090
Informix has number of inbuilt date functions which you can use and also makes use of positions for grouping and ordering

For example if salesdate in following is defined as a datetime in database this can be converted to a date by using date function

SELECT Area, date(SalesDate), SUM(SalesAmount) FROM Sales
Group By Area, 2
Order by Area, 2

Cannot group or order by function but can by position function appears in.

Also year, week, day functions for manipulating dates.


0
 

Author Comment

by:bozer
ID: 21769104
Thank you, so let's say I have this table:

Date                                     Total
2008-05-30 18:39:11.705     3
2008-06-04 15:33:04.267     4
2008-06-04 18:33:04.267     2
2008-06-05 13:16:10.912     1
2008-06-05 14:40:50.751     5
2008-06-05 14:51:45.001     4
2008-06-05 19:00:33.626     1
2008-06-06 10:29:12.463     7

How do I get this result?

Date                       Sum
2008-05-30              3
2008-06-04              6
2008-06-05             11
2008-06-06              7


Thank you
0
 
LVL 2

Accepted Solution

by:
TheLastStraw earned 100 total points
ID: 21769256
Simplest way to manipulate and get data as expected  is assuming your date field is actually datetime type

select extend(NameOfDateTimeField, year to day), Sum(FieldToSum)  from YourTableName
group by 1

or else

select extend(NameOfDateTimeField, year to day) date, Sum(FieldToSum)  sum from YourTableName
group by 1


This will display exactly as your sample putput above.  Earlier versions of Informix didn't have datetime but if you have it you will have extend function available.  String value after field names or function used to alias field but if your are embedding this in program you can drom those.
0
 

Author Closing Comment

by:bozer
ID: 31466136
Worked like charm, thank you :)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question