Solved

string manipulation in informix tsql

Posted on 2008-06-11
4
1,666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…

717 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