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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q about sql syntax

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
0
0
NL
Hi!

My view has among others an "property ID" (integer).

In a listbox I do make a selection of several property-id's
I retrieve e.g "12","25","30.
As it is a listbox these are all characters
of course the comma can be a digit as needed

Q:
What is syntax of this pseudo code:

Select * from myView where myView.nProperty = one of "12","25","30"

I know this can be done with subquery, but how?

TIA
-Bart
 
You're looking for IN:

SELECT * FROM myView WHERE ;
.nProperty IN "12","25","30"

 
In addition:
I do have a table holding properties of people.
On a dataform you can give a person one or more properties.

This way three tables are involved:
- table holding properties
- table holding person data
- table holding many-many data

my goal is to have a query of people based upon certain properties.
that way I get all persons available having a property with eg ID 12 or ID 25 or ID 30.

I understand the given answer but how to generic get my selection (taken from listbox) into the SQL statement.
Would it be a solution to roll "12","25","30" into a var?
eg lcItems=["12","25","30"]

eg
select distinct name,street,pcd,place from myView into myCur where allt(str(nProperty)) in lcItems
distinct as people can have more than one property and I want them only once in the result
(It's a bit weird due to mixing up integers witch character value)
-Bart
 
WHERE allt(str(nProperty)) in (&lcItems)

would work, it's jsut limited to a certain amount of IDs, IIRC 27.

You can always do an IN clause as an inner join, and I would prefer that, even if you seldom will need more than 27 IDs, because it avoids the macro substitution.

...FROM yourtable INNER JOIN joincursor on yourtable.ID = joincursor.ID

And then you just need to insert the selected IDs into the joincursor.

Bye, Olaf.

 
Olaf,
Thanks for feedback.
With som trial on error I just found the solution with the macro substitution.
Especially the innerjoin I was looking for as this is imho more generic but due to my lack of knowledge on that part I needed you here.
Thanks again!
-Bart
 
Well,

I already gave the syntax. As an extended sample:

Code:
create cursor joincursor (ID I)

*insert user selection in that cursor.

select distinct name,street,pcd,place from myView;
inner join joincursor on myView.ID = joincursor.ID;
into cursor myCur

Cursor creation of the joincursor wouldbe put at form.load or init perhaps. Filling in the user selections from the listbox into the cursor can be done as you like, you can also switch to a construct of two listboxes, moving selections from left to right, then the join cursor could also be the controlsource of the listbox displaying the selected items.

And then the SQL part is simply using the selections themselves to inner join and thereby filter the view records.

Bye, Olaf.
 
Here's another variation:
Code:
create cursor joincursor (ID I)

*insert user selection in that cursor.

select name,street,pcd,place from myView;
where myView.ID in (select ID from joincursor);
into cursor myCur


- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top