Solved

Pervasive SQL query

Posted on 2014-07-18
4
258 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

695 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