Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
13
Erster Beitrag:
vor 8 Jahren, 3 Monaten
Letzter Beitrag:
vor 8 Jahren, 3 Monaten
Beteiligte Autoren:
Hans60, Piet van Zanten, "Marcel Berman".pcs.crosspost, Jeff Graham

search multiple items in one string

Startbeitrag von Hans60 am 27.09.2009 21:09

I have the following issue I am stuck with,,

Database table and search Edit field

I like to enter a several strings to be searched separeted by space or by comma,
I have tried the folowing code but this does not work. Does some one have a idea how I could do it.

sNewList is string = EDT_SearchInput
sAPID is string
IF sNewList > "" THEN
FOR EACH STRING sAPID OF sNewList SEPARATED BY " " // or “ “ (space)
TableSeek(Table_aport,TableSeek(Table_aport,sAPID))
END
END


Thanks for any help
Hans

Antworten:

Hi Hans,

If you are trying to select multiple rows, then you need
TableSelectPlus(TablePaport,TableSeek(TablePaport,sAPID))
Be sure your table allows multiple selection.

If not, then what result do you want?

HTH,
Jeff

von Jeff Graham - am 30.09.2009 02:34
Hi Jeff,
what I am trying to do is search same column for multiple instances.
For example I like to search name field for 3 names separated by space.
At the moment I have the search field searching for one name at the time. In order to speed up things I like to enter 3 names and all 3 would be listed after the serach.

Thanks for your help
Hans

von Hans60 - am 08.10.2009 08:58
Hi !
I think that you should build a query dynamically, something like

local
MyQuery is a string = "select * from thisfile"
MySelection is a String = "Peter John Mary"
aName is a string = ""
MyCondition is a string = ""

for each string aName from MySelection separated by " "
MyCondition += [" or "] + "name = '"+aName
end
if MyCondition "" then
MyQuery += " where " + Mycondition
end
and then execute the query ...

Pay attention, I use the french version and I am not too sure that the
translation is correct.

hope this help.

--
Marcel Berman
Président de Be-Dev.be
l'association francophone belge des utilisateurs de
WinDev, WebDev et Windev Mobile
Message forwarded from pcsoft.us.windev

von "Marcel Berman".pcs.crosspost - am 08.10.2009 16:10
Hi !
Sorry there is an error in the line :

> MyCondition += [" or "] + "name = '"+aName

it should be :
MyCondition += [" or "] + "name = '" + aName +"'"

Sorry again

--
Marcel Berman
Président de Be-Dev.be
l'association francophone belge des utilisateurs de
WinDev, WebDev et Windev Mobile
Message forwarded from pcsoft.us.windev

von "Marcel Berman".pcs.crosspost - am 09.10.2009 08:11
Hi Marcel
thanks for your sample code. It is the first time that I am confronted with
WD Queries. I have consulted the book and read about insert queries select queries
etc. The book mainly uses the Query tool to select and compile the desired result.
Here a few questions and perhaps you have the time to calify a few things. I
have added some comments behind your code where I am stuck.




local
in
the book it starts mainly with "Select" what do you mean
by local?


MyQuery is a string = "select * from thisfile"
"select
* from thisfile" ------> do you mean something like "DATABASENAME.COLUMN"
? I guess if I use a search field I have to skip the "


MySelection is a String = "Peter John Mary"

variables
are normally decleared at the beginning is this another method of
doing it or does it have to be that way in SQL


aName is a string = ""
 


MyCondition is a string = ""
 


MyCondition is a string = ""
 


for each string aName from MySelection separated
by " "
 


MyCondition += [" or "] + "name
= '"+aName
 


end
 


 
 


and then execute the query
HExecuteQuery
// HExecuteSQLQuery




Where does that code go in to the execute button or query editor?

Many thanks
Hans

von Hans60 - am 12.10.2009 13:29
Hi Marcel
thanks for your sample code. It is the first time that I am confronted with
WD Queries. I have consulted the book and read about insert queries select queries
etc. The book mainly uses the Query tool to select and compile the desired result.
Here a few questions and perhaps you have the time to calify a few things. I
have added some comments behind your code.




local
in
the book it starts mainly with "Select" what do you mean
by local?


MyQuery is a string = "select * from thisfile"
"select
* from thisfile" ------> do you mean something like "DATABASENAME.COLUMN"
? I guess if I use a search field I have to skip the "


MySelection is a String = "Peter John Mary"

variables
are normally decleared at the beginning is this another method of
doing it or does it have to be that way in SQL


aName is a string = ""
 


MyCondition is a string = ""
 


MyCondition is a string = ""
 


for each string aName from MySelection separated
by " "
 


MyCondition += [" or "] + "name
= '"+aName
 


end
 


 
 


and then execute the query
HExecuteQuery
// HExecuteSQLQuery




 
Where does that code go in to the execute button or query editor?


von Hans60 - am 12.10.2009 13:33
Hi Marcel
thanks for your sample code. It is the first time that I am confronted with WD Queries. I have consulted the book and read about insert queries select queries etc. The book mainly uses the Query tool to select and compile the desired result. Here a few questions and perhaps you have the time to calify a few things. I have added some comments behind your code.



Where does that code go in to the execute button or query editor?

Thanks
Hans

von Hans60 - am 12.10.2009 13:52
Hi Hans,

If you use the query editor/wizard you can define a condition as follows:

- select the item that you want to use in your condition
- click on the last empty column and from the popup select "new condition"
- for the condition select "is in the list", "supplied by the parameter"
- enter a parameter name for the list of values

Now you can supply a list of values, separated by semicolon or TAB or CR

Bind your table to the query and in the table initialization code put:

sParam is string
sParam=replace(edt_Search," ",Tab) //replace spaces by tabs
hExecuteQuery(qry_MyQuery,hQueryDefault,sParam)

Assuming edt_Search contains the search string entered by the user.
To refresh your table use TableDisplay(Table,taInit)

If search string is empty, all records are returned by the query.

I just typed the code here, so the syntax is not checked.

HTH, regards,
Piet


von Piet van Zanten - am 12.10.2009 14:23
Piet , what I dont get is:

"Now you can supply a list of values, separated by semicolon or TAB or CR "

According my understanding do the serach parameters come in my case from the "EDT_SearchInput" field. However, if I leave the "Parameter name:" field empty then I can not vaildate.



von Hans60 - am 12.10.2009 15:16
Hi Hans, what do you mean by validate?


von Piet van Zanten - am 12.10.2009 19:24
Piet,
you wrote
"Now you can supply a list of values, separated by semicolon or TAB or CR "

I do not want to add any specific name to filter on that info should come frome the EDT_SearchField. If I however leave it open then I am not able to complte that step in the query.

Thanks

von Hans60 - am 12.10.2009 20:52
Hi Hans,

For the item sAPID in the query you set the condition to be a list of values.
Name the corresponding parameter in the query editor any name you like, e.g. Param_list.
Now you can use the code I supplied to pass the value of your edit field to the query in the Table Initialization code:

sParam is string
sParam=replace(EDT_SearchInput," ",Tab) //replace spaces by tabs
hExecuteQuery(qry_MyQuery,hQueryDefault,sParam)

Now sParam is passed to the query and it will return all sAPID's
Remember that the table now has to be a browsing table, bound to the query you defined.
Can't be any clearer than that I'm afraid.

Regards,
Piet



von Piet van Zanten - am 12.10.2009 21:26
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.