Solved

Pervasive SQL query

Posted on 2014-07-18
4
254 Views
Last Modified: 2014-07-18
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
Comment
Question by:classnet
[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 28

Expert Comment

by:Bill Bach
ID: 40204633
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
 

Author Comment

by:classnet
ID: 40204677
I am doing this through ODBC and thus cannot access the database to create stored procedures.
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
ID: 40204868
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
 

Author Closing Comment

by:classnet
ID: 40204926
You are correct... we are using Timberline.
I will attempt to use your soltion
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

739 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