INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

PSQL and Variables - How do I use them in queries?

PSQL and Variables - How do I use them in queries?

(OP)
Hello,
I have written a simple query to generate appraisal details for Department members it is as follows.

select distinct
DP.DepartmentReference Reference,
DP.DepartmentName Name,
(select count(DM.PersonKey)DepartmentMembers from DepartmentMembershi DM
    where DM.DepartmentKey = DP.DepartmentKey),
(select
count(DM.PersonKey) Appraised
from DepartmentMembershi DM,Appraisal AP
where
DM.DepartmentKey = DP.DepartmentKey and
DM.PersonKey = AP.PersonKeyAppraisee and  
AP.AppraisalDate > (select
BP.StartDate
from
BudgetingPeriod BP
where BP.StartDate < CURDATE ( ) and BP.EndDate >= CURDATE ( )
and BP.Subcode = '')  and
AP.AppraisalDate <= (select
BP.EndDate
from
BudgetingPeriod BP
where BP.StartDate < CURDATE ( ) and BP.EndDate >= CURDATE ( )
and BP.Subcode = '')
and AP.AppraisalStatus ='ACTU'
and AP.AppraisalType = 'ANNL'),
PD.DepartmentReference DeptAbove
from
Department DP

Left Outer Join   Department PD
on
DP.DepartmentKeyDepar  = PD.DepartmentKey


As you can see I only require Appraisal that occur in the current budged period. Can I assign the start and end dates of the current period to variables and use these instead in the query?
Thanks in advance

Pervasive 9.5.


David Ison

RE: PSQL and Variables - How do I use them in queries?

Variables are possible.  How you do them depends on a few things including the actual interface and programming language.  Generally speaking, you could use either parameters from your code or you can use a Parameterized Query.  
Take the pseudo-code below for parameters from code:

CODE

string StartDate = "2008-04-06";
string sSQL = "select * from table where fldStart = '" + StartDate + "'";

A Parameterized Query is something more like:

CODE

PsqlParameter param;
param.value = "2008-04-06";
PsqlCommand cmd;
cmd.commandtext = "select * from table where fldStart = ?";
cmd.parameter.add (param);

I might have some better code once you post up the language and interface you're using.

 

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

RE: PSQL and Variables - How do I use them in queries?

(OP)
Thanks I understand both examples. Once again thankyou for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close