Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 4 Jahren, 8 Monaten
Letzter Beitrag:
vor 4 Jahren, 8 Monaten
Beteiligte Autoren:
Allard, Jose Antonio Garrido, Peter Holemans, Lewi

search on multiple leys

Startbeitrag von Allard am 11.11.2013 09:26

Hi I want to search on several keys. SO I made a for each loop with all the parameters. Well if one selects a value for all the search parameters then the search goes fine but if one selects onley one a Null value fault appears. Witch is ofcource is to be expected.

I can make a whole lot of if value statements and define a for all search for all possible senario's but that's a lot of coding.

Is it possible to define a value that gives all values like a "* " so in case that there is no value entered no null exception appears

Thanks

Allard

Antworten:

Hi.

I don't understand how are you using a FOR LOOP.
When I want to search on several keys, i use hexecutequery(nameofthequery).
Previusly I initialice each of the query parameters via nameofquery..nameofparameter
If i set a paramter = null, then the query ignores the parameter.

Regards,
José Antonio.

von Jose Antonio Garrido - am 11.11.2013 16:16
Hi thanks thatis just what I needed to know.

Well I used it like this:

For all filename where "seachkey="+ edt-field + "searchkey="+ edtfield etc

This does work but the value cannopt be empty for then a Null error appears.

So if I define a query on the file with parameters and do A little coding telling the query if a value is entered or not and if no alu than parameter is Null than it should work?

Ok thanks

regards

Allard

von Allard - am 11.11.2013 16:40
Here an examble für 3 Fields: FIELD_MARK, FIELD_OWNBID, FIELD_DATE


// Global (Window-) Variables
FilterItem is array 3 Variants
_ITEM_MARK is int = 1
_ITEM_OWNBID is int = 2
_ITEM_DATE is int = 3
---------------------------------------------------


Procedure RunQureryWithFilter()
FilterItem[_ITEM_MARK] = FIELD_MARK..Value
FilterItem[_ITEM_OWNBID] = FIELD_OWNBID..Value
FilterItem[_ITEM_DATE] = FIELD_DATE..Value

// Check for empty values and set to Null
IF FilterItem[ITEM_MARK] = 0
FilterItem[ITEM_MARK] = Null
END
IF FilterItem[ITEM_OWNBID] = 0
FilterItem[ITEM_OWNBID] = Null
END
IF NoSpace(FilterItem[ITEM_DATE]) = ""
FilterItem[ITEM_DATE] = Null
END

SetQuerryParameter( false)
hExecuteSQL(QRY_FZG)
....




PROCEDURE SetQuerryParameter( bClear is boolean)
IF bClear THEN
// clear FilterItems and get all Recs with hExecuteSql
QRY_FZG.FILTER_MARK = Null
QRY_FZG.FILTER_OWNBID = Null
QRY_FZG.FILTER_DATE = Null
ELSE
QRY_FZG.FILTER_MARK = FilterItem[_ITEM_MARK]
QRY_FZG.FILTER_OWNBID = FilterItem[_ITEM_OWNBID]
QRY_FZG.FILTER_DATE = FilterItem[_ITEM_DATE]
END
RETURN


von Lewi - am 11.11.2013 20:55
Exactly Allard.

For example, thit will search for all invoices of this year.
MyQueryInvoice..ParamName = null
MyQueryInvoice..ParamDateStart = "2013/01/01"
MyQueryInvoice..ParamDateEnd = "2013/31/12"

And this will search for all invoices of people containing "jose" in his name.
MyQueryInvoice..ParamName = "jose"
MyQueryInvoice..ParamDateStart = null
MyQueryInvoice..ParamDateEnd = null

Regards,
José Antonio.

von Jose Antonio Garrido - am 11.11.2013 22:08
Hi all,

Just as an add-on: you don't need to explicitely set a query parameter to 'null' to have the runtime engine ignore the parameters.

Just by NOT initializing a query parameter, it will not be used by the query interpreter.
This gives less code.

The same way I tend to create generic queries with all possible parameters and thus query values (Sometimes up to 30): code once, use anywhere... Next I often initialize only one parameter when using the query.

Cheers,

Peter H.

von Peter Holemans - am 12.11.2013 08:13
Hi all,

Thanks for the response. Yes Peter I found that out as well . That's cool.

I did exacly like Jose said. I works like a charm.

regards

Allard

von Allard - am 12.11.2013 12:28
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.