Home > AS/400 Tips > WebSphere Strategies for iSeries professionals > Finding the Value in SQL and WebSphere
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WEBSPHERE STRATEGIES FOR ISERIES PROFESSIONALS

Finding the Value in SQL and WebSphere


Paul Holm and Colin Slade
05.20.2004
Rating: -4.85- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


SQL and JDBC are the standard language for relational database management systems. SQL statements are used to perform tasks such as selects, updates, inserts, and deletes from a database. Most Web applications built for WebSphere make extensive use of SQL. A frequent problem encountered for Web application development is when attempting to allow optional selection criteria.

Problem:
Many applications allow the user to select records based on selection criteria. Let's say you need to create an application that allowed users to search for used truck trailers. We wanted to allow them to specify a dynamic range of selection criteria. For example: Select based on trailer type, cost, state, age or any combination of these.

If they don't specify criteria, the search should ignore it. That is the big trick, how to ignore it if they don't specify a value.

This article will detail how this type of search can be coded and also how to ignore values in the search if the user does not specify them.

[TABLE]
[IMAGE]

SQL does not like null values and will normally not take one unless specifically stated in the SQL expression. So for the example with used trailers, you want to get the user to select based on trailer type, cost, state, age or any combination of these. To do that you would use a normal select statement with the ? To get input from the user, an example might be this:

The problem with that statement is it requires both conditions to evaluate to true. What happens if the user does not specify a cost? The answer is they would get no records returned, which is not what we want. If you use the AND statement like above you must enter both values to get a valid selection from the table. This significantly narrows your search so that none of your options can be blank or nu


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
Web Tools
Programming for the Web on the IBM i, what is possible
Zend Web software teams up with IBM System i
Using geocoding on AS/400 to enhance your Web presence
The iSeries Blog has a new home on IT Knowledge Exchange
The best technologies and tools for System i programmers in 2009
Search400.com Products of the Year 2008
Application modernization strategies for System i
Natively supported Web applications for Power running i
System i PHP authoring tool tries to fill void in Web-coding know-how
Lazy coder: What does PHP on the i5 mean?

Web Servers
System i no longer the stepchild of IBM's world
Connecting WebSphere to AS/400 for image retrieval
Weaving in WebSphere
SOA enhancements drive IBM WebSphere feature packs
SOA means money for IT workers
Enable J2EE app on WAS to access DB2
Securing Apache: Keeping patches current
IBM runs USOpen.org on Power boxes
MoMA's IT makeover a mix of old and new
How does RPG talk to a browser?

Web Development
Groovy programming on IBM i
Running PHP open source applications: NOBODY needs authority
Zend Web software teams up with IBM System i
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
AS/400 lessons from the past, present, and future: A holiday tale
Application modernization strategies for System i
RPG application modernization for i5
Web skills crucial to iSeries programmer professional development
System i Web interface could boost the platform

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
WebSphere Development Studio Client (WDSC)  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


ll.

Solution:
The solution to this problem is the VALUE function provided in SQL. The VALUE function returns the first argument in a list that is not null. The arguments are evaluated in the order in which they are specified, and the result of the function is the first argument that is not null. The result can be null only if all the arguments can be null, and the result is null only if all the arguments are null. The selected argument is converted, if necessary, to the attributes of the result. Here is an example:

This example selects all of the rows from the trailer table where trailer type and cost are taken from the user the input. The SQL statement is prepared using standard Java prepared statements. The input if specified is cast into a decimal number and returned as the comparison operand. If the user did not specify a value, then the current value of the field itself is used which effectively would result in a true condition in all cases. The VALUE function results in these comparisons if no values are entered by the user.

As you can see from this SQL, it would result in all records being return, which is the desired result. If the user specifies only one of the two criteria, then only the one specified is used as part of the selection criteria.

Here is a Web site example: www.wabashusedtrailers.com.

Conclusion:
When creating Web applications it is important to give the user the ability to specify selection criteria but not necessarily require it. With the SQL VALUE function you are able to accommodate such a requirement, resulting in a effective and flexible WebSphere application. Put this tip to use and unleash the VALUE in your application.

---------------------------
About the authors: Paul Holm is a former IBM-Rochester WebSphere, Java, and DB2 developer/consultant. He specializes in helping iSeries RPG shops develop Web-based applications. Paul is currently a lead architect for the "WOW" product, which is Query/400 and DFU for WebSphere (aka WebSphere on steriods). Paul can be reached at pholm@planetjavainc.com.

Colin Slade is a Web developer at PlanetJ Corp.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts