[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: Question on a dynamic where statement



Doris

I'm using a variable in the where clause, and I can include different
fields, my code is something like that

    Let $ExtraWhere = ' AND'
    If #Classification > 0
      Let $ExtraWhere = $ExtraWhere || ' AND A.U_PRIORITY = ' ||
to_char(#Classification)
    End-If
    If $CityName != ''
      Let $ExtraWhere = $ExtraWhere ||  ' AND C.CITY = "' || $CityName ||
'"'
    End-If
....
   Begin-Select
      (fields)
   From
      (tables)
   (Conditions)
    [$ExtraWhere]

here you can see, two diffrents fields, the first is a number field, and
the second is an string field

good luck    (Buena Suerte)
Rodrigo




 (Embedded
 image moved   "Doris K. Brinson" <DBrinson @ COMMHOSPINDY.ORG>
 to file:      06/10/98 08:00 PM
 pic04522.pcx)




Please respond to SQR-USERS@USA.NET

To:   Multiple recipients of list SQR-USERS <SQR-USERS @ list.iex.net>
cc:    (bcc: Rodrigo Andaur/LACD/CL/Unisys)
Subject:  Question on a dynamic where statement




Is there a way using SQR to use a variable as the where statement in a
select command.  I am trying to write a label program that will allow the
user to enter either an emplid, department or location. Depending on what
the user entered, I want to select the appropriate data. I can easily set a
variable to say
  let $whereclause = 'WHERE DEPTID = $entered_dept'

SELECT (lots of fields)
FROM PS_EMPLOYEES
$whereclause

But where I run the above type code, I get an SQL error.  I know the easy
way would be to write different selects for each of the allowed criteria,
but I think there has to be a better way.

Doris

pic04522.pcx