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

Re: How can this be done??



> Hi All,
>  I have this question. I have a select statement which has an IN clause, for eg.
>
> select emp_iid
> from emp
> where dept in ('HR',ENG')
>
> This is the problem. I would like to have th IN clause parameters to be a
> variable number. I have an upper limit though (say 10) I dont know how many
> different Dept's i might have to include. I tried passing all the depts as a
> comma seperated string. I UNSTRING them into 10 different variables and them
> make them into a string like 'HR','ENG','SALES' (including the ' and , ) say
> $Dept. so now the select clause could look like as
> select emp_iid where dept in ($Dept).
> This apparently does not work. Does anybody have any suggestion for this kinda
> problem?


Raja,

What you're trying to do is called a "dynamic query".  To include
variable text in the where clause, put square brackets around
the variable containing the text.  For example:

   where dept in ( [$dept] )

The square brackets tell SQR to treat the contents of the variable
as part of the literal SQL statement, not as a host variable.

Ray
----------------------------------------------------------------------
Ray Ontko       |  Ray Ontko & Co  |  "Ask me about SQR and the WEB."
rayo@ontko.com  |  Richmond, In    |  See us at http://www.ontko.com/