Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

dison123

Programmer
Feb 29, 2008
5
0
0
GB
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
 
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
 
Thanks I understand both examples. Once again thankyou for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top