Solved

Pervasive SQL query

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now