Domain Builder

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 24 January 2008

If Statements Using SQL

Posted on 23:44 by Unknown
When building list windows for users you often want to allow them to specify search criteria. If the search criteria are simple and only have a single field or all fields must be entered than a simple WHERE clause with retrieval arguments will do the job.

For very complicated arguments with multiple selections you will have to resort to dynamically altering the SQL behind the datawindow. But you may not realize that if you do not require multiple selections for a single field then with some clever SQL coding you can avoid time consuming dynamic SQL.

For example if we were building a selection window for employees, you may want to allow the user to search based on employee number, employee name, Address or any combination of the three. We can achieve this by declaring three retrieval arguments of the correct datatypes. In your retrieve script on the window you would have designed the arguments input criteria using a datawindow! so you could select the empty field is null option of the edit control. If you have not and shame on you then if the field is empty you will need to manually set it to null.
Then in the SQL you would code for the NULL values:
SELECT emp_no, emp_name, emp_addr1, emp_telno
FROM employee
WHERE ( emp_no = :al_emp_no OR :al_emp_no IS NULL )
AND ( emp_name = :as_emp_name OR :as_emp_name IS NULL )
AND ( emp_addr1 = :as_emp_addr OR :as_emp_addr1 IS NULL )
You would also want to concatenate '%' on to the end of the strings to allow for pattern matching and convert both sides of the comparison to Lower case to make it more user friendly, you would convert the retrieval argument to lower case once in Powerscript and pass it to the datawindow:
( Lower( emp_name ) LIKE :as_emp_name...
Email ThisBlogThis!Share to XShare to Facebook
Posted in Database | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Using Windows Scripting Host
    You can use Windows Scripting Host on PowerBuilder for many purpose. On sample code below, you can use it to get the network domain, user na...
  • List available ODBC datasources
    You can list available ODBC datasources from within PowerBuilder. You need to declare the following external functions : FUNCTION integer SQ...
  • Sorting Datawindow
    Here's a script to sort datawindow rows when the column header is clicked as in windows explorer. Requirements : Column header should be...
  • Faster Exist Checking in Oracle
    When performing checks in business logic to see if a record is used as part of a foreign key in a child table people often opt for the Selec...
  • Return Code on Application Exit
    Sometime when a PowerBuilder application is called by other program or a shell script, programmer want a return code after exiting the Power...
  • Keeping Column into Array
    With this simple tips you can keep all the column name on DataWindow into an array int colNum, numCols string colName[] numCols = Integer(dw...
  • Julian Date
    Here's a function to calculate Julian Day number for the specified day, month, year. If the year is B.C. it must be negative. /* public...
  • Getting Computer Name
    You can get the computer name from within the application. Declare the Win32 API modul on Declare -> Local External Functions Function bo...
  • Get a list of printers installed
    In this example, we populate a listbox with the printers name /* Get Printer List */ string printers[] int rtn, i, nbPrinters rtn = Registry...
  • Calling Oracle Stored Procs/Functions from PB
    Whenever you want to make a call to an Oracle stored procedure or stored function, a good approach is to first declare it as an external fun...

Categories

  • Database
  • DataWindow
  • PowerScript
  • Win32 API

Blog Archive

  • ▼  2008 (34)
    • ►  March (14)
    • ►  February (1)
    • ▼  January (19)
      • Avoiding "Double" Error Messages in DW Validation
      • Capturing Special Keys on your DataWindow
      • Center a Response Window
      • If Statements Using SQL
      • Run an Application Only Once
      • C/C++ Datatype Conversion
      • Registering OCX Components in an Exe
      • Get The Name of a Network Share
      • Get Volume Information
      • Mapping a Network Drive
      • Getting Active Directory
      • Getting Computer Name
      • Sending Key Press
      • Sending Hexadecimal Character to Printer
      • Calling an Internet Browser from Application
      • Getting Date Format from Windows Registry
      • Return Code on Application Exit
      • Sitemap
      • Privacy Policy
Powered by Blogger.

About Me

Unknown
View my complete profile