[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Pervasive SQL query

Suppose I am working on a people table.
I want to return the names of people.
I'm looking to prompt the user 3 times (don't ask... long story).

Based on the results of the prompts I'll return:
The names of everyone (Prompts 1, 2 and 3 are 0)
or, if Prompt1 <> 0 those who are Prompt1 years old.
Unless Prompt2 <> 0 then I want all names that are >= Prompt1 and <= Prompt2.
Unless Prompt3 <>0.  Then it could be >= Prompt1 and <= Prompt2 AND = Prompt3.

Answers would be, perhaps:

Everyone
or
Everyone who is  35
or
Between 35 and 45
or
Between 35 and 45 AND all those age 60.

This is actually a construction accounting query that is using cost codes... I just thought that people and ages would be a simpler example to provide.

Using Pervasive 11
0
classnet
Asked:
classnet
  • 2
  • 2
1 Solution
 
Bill BachPresidentCommented:
I would expect this to be a fairly simple extension to this issue:
    http://www.experts-exchange.com/Database/MS-SQL-Server/Q_28478909.html

Extending either the accepted solution (by adding terms to the WHERE clause that exactly mirror your criteria above) or the unaccepted solution (where you could use IF statements to create the correct WHERE clause based on the input values) would work.
0
 
classnetAuthor Commented:
I am doing this through ODBC and thus cannot access the database to create stored procedures.
0
 
Bill BachPresidentCommented:
You mention "construction" -- are you using Timberline?  Timberline uses a custom ODBC driver (i.e. NOT the Pervasive one), so I would have to agree with you -- stored procedures are not likely possible.  However, with any other database using the PSQL ODBC drivers, you should be able to issue the CREATE statement through ODBC just fine.  In fact, the PSQL installer does this very thing when it creates the DemoData and PervasiveSysDB databases using the "pvddl" utility.  Just put the CREATE statement into a text file and pvddl does the rest.  (If you need to modify the proc, issue a DROP PROCEDURE statement first in the file.)

The logic you need to do this from the WHERE clause is complicated, but not impossible.  You will have two components to each of your restrictions -- the restriction itself and the selection criteria.  Here's an example:
WHERE -- First criteria
((Prompt1=0 AND Prompt2=0 AND Prompt3=0) AND (1=1))
OR  -- Second Criteria
((Prompt1<>0 AND Prompt2=0 AND Prompt3=0) AND (age=35))
OR  -- Third Criteria
((Prompt1<>0 AND Prompt2<>0 AND Prompt3=0) AND (age >= Prompt1 AND age <=Prompt2))
OR  -- Fourth Criteria
((Prompt1<>0 AND Prompt2<>0 AND Prompt3<>0) AND ((age >= Prompt1 AND age <= Prompt2) OR age=Prompt3))

Obviously, you can tweak things and try to optimize if you wish -- but sometimes brute force is the simplest to write AND understand later.

Note that PSQL probably won't do a very good job of optimizing this query, and this query will likely run a full table-scan to look at every record.  If your data set is large, it will take a while.
0
 
classnetAuthor Commented:
You are correct... we are using Timberline.
I will attempt to use your soltion
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now