[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

string manipulation in informix tsql

Posted on 2008-06-11
4
Medium Priority
?
1,697 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 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