TechTalk: Using character functions in Query and SQL on numeric fields.

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

I'd like to illustrate the method I use to have the substring functions in Query/400 and SQL work on a numeric field. My example operates on an order file, and what I'm going to demonstrate is how to extract the year out of a numeric date. To accomplish this, I use a combination of the DIGITS function and the SUBSTR function in Query/400.

In my example order file, I have a field called FDATE. Because FDATE is numeric, Query (and SQL) cannot use SUBSTR to extract the year. Fortunately, with the help of the DIGITS keyword, my query is able to convert FDATE to an alphanumeric value, which then allows the query to perform a substring. In 2, you can see how to combine the two keywords. The result of the expression is placed in a field I defined in Query/400 and called YEAR.

In my example order file, I have a field called FDATE. Because FDATE is numeric, Query (and SQL) cannot use SUBSTR to extract the year. Fortunately, with the help of the DIGITS keyword, my query is able to convert FDATE to an alphanumeric value, which then allows the query to perform a substring. In Figure 2, you can see how to combine the two keywords. The result of the expression is placed in a field I defined in Query/400 and called YEAR.

Now I can simply use the YEAR variable I just created to select records from the file for the year 95. You can see an example of the selection process in 3. The method I've come up with is simple, and it also works in SQL.

Now I can simply use the YEAR variable I just created to select records from the file for the year 95. You can see an example of the selection process in Figure 3. The method I've come up with is simple, and it also works in SQL.

- Jean-Jacques Risch

TechTalk: Using character functions in Query and SQL on numeric fields.

Figure 2: Using Functions to Extract the Year from a Numeric Date


TechTalk: Using character functions in Query and SQL on numeric fields.

Figure 3: Using Resulting Character Year Field


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: