Create Search Function including AND OR vb .net - sql

Hope you can help me out and inspire me here
I am looking to create a Search function that searches through a datagridview column looking for key words and then filtering based on the result. I have done this already and it works fine. However this is based on the user entering strings into the textbox separating their strings with a comma. So an example would be
A DataGridViewColumn with 3 values
ERROR_QUEUE_MAY05
ERROR_QUEUE_MAY06
ORDER_QUEUE_JAN01
The User then enters the search criteria
ORDER, 06
And the result would be
ERROR_QUEUE_MAY06
ORDER_QUEUE_JAN01
As you can see the filter has used an OR to filter the column
I want the user to be able to use brackets () and also AND statements like you would in a SQL statement so they could use for example
("ORDER" AND "MAY") OR "03"
This would filter the results to show anything with ORDER and MAY in the title or 03.
Has anyone done anything like this in the past or have any ideas of going about it?
Thanks All

One approach is to scan the string from left to right, then recursively call the evaluator every time parentheses are encountered. After a recursive call, replace the parenthesized expression with "true" or "false". If you intend to allow and a higher priority than or, you can treat that recursively as well.

Related

SQL - After group by filtering down to rows where column value = certain string

Not sure why this isn't working.
When I run the query without HAVING segment ilike 'Enterprise' I get results (see screenshot) but when I add it back in the query returns nothing despite clearly containing instances where segment = 'Enterprise'. I can't find any instances online where having is used to filter for strings so I'm thinking this just isn't possible. Could someone confirm if this is the case and if there is an alternative method if so? Thanks.
You can't use HAVING to filter for strings, you can only use it to filter for numeric values. To filter for strings, you'll need to use the WHERE clause.

Filter for "contains text" with OR or CASE to allow multiple options in NetSuite. Custom field: Keyword Match option seems available

NetSuite formula(text) problem.
I have a specific search I need to power up but I could also really use this for general use across a few types of reporting.
We use a lot of custom body fields which do not seem to have access to the Keyword Match option in the dropdown system or I would be using commas left and right.
I need to search a single custom field for multiple possible answers.
I was thinking maybe a CASE WHEN formula but I don't have an else.
Lets call the field states. I want this report to only return rows of records where there are the following 5 states in the custom body field "Shipping State". it isn't allowing keyword match. I only want to see transactions with Michigan, New Jersey and Floria (this is hypothetical) so I want just to put a filter in up front to pair down the results.
CASE WHEN {custbody.shippingstate} IS 'Michigan' ...
Can I use an OR construct here? and do I need an else?
I tried using coalesce but I don't think I had the syntax around the coalese right.
Any help for a formula newbie appreciated.
Try the following as a formula text result column in a NetSuite saved search.
CASE WHEN LOWER({custbody.shippingstate}) LIKE '%michigan%'
OR LOWER({custbody.shippingstate}) LIKE '%jersey%'
OR LOWER({custbody.shippingstate}) LIKE '%florida%'
THEN 'Y' END
LIKE conditions are case sensitive, so that's why I incorporated the LOWER() method. Reminder in NetSuite "%" matches any string of any length (including zero length, and "_" matches a single character. If this works as a results column you can add the formula text as a criteria to filter results.

IIf Statement only manipulating part of the data in a field

I created an IIf statement in a MS Access query, to fill null spaces in a particular field. The statement in only affecting some of the data, but not all. Why would it only work on a certain percentage of the records?
Field:Line_off_Date
Table:Claims
Criteria:IIf(IsNull("Line_off_Date "),"1/1/1900"
Here is the official Sql after delimiting:
SELECT Claims.Line_off_Date
FROM Claims
WHERE (((Claims.Line_off_Date)=IIf("Line_off_Date IsNull",#1/1/1900#,"Line_off_Date ")));
I can't screen shot onto this site, but I could give a mock up representation:
Line_off_Date
12/23/2013
12/23/2013
5/16/2010
1/1/1900
1/1/1900
12/10/2000
11/4/2008
This is listed as a column, with a space between 1/1/1900 and 12/10/2000. When I post it here, it turns into a paragraph. I hope this helps in some way...
I'm unsure about your goal, but this looks like something where you could use the Nz Function.
Criteria: Nz(Line_off_Date, "1/1/1900")
If you want IIf instead, try it this way ...
Criteria: IIf(Line_off_Date Is Null, "1/1/1900", Line_off_Date)
Note those suggestions assume Line_off_Date is text datatype. If it is actually Date/Time, delimit the value with # instead of quotes.
Criteria: Nz(Line_off_Date, #1/1/1900#)
Criteria: IIf(Line_off_Date Is Null, #1/1/1900#, Line_off_Date)
I'm more confused after seeing your WHERE clause ...
WHERE (((Claims.Line_off_Date)=IIf("Line_off_Date IsNull",#1/1/1900#,"Line_off_Date ")));
Aside from the issues of quoting and so forth, I think the logic is faulty. If you say "show me rows where Line_off_Date = something other than what is stored in Line_off_Date", you may not get any rows back.
I think you need a different approach. If you need more help, show us a brief set of sample data and your desired output based on those data.
Based on the comment discussion, my understanding is you don't really want to filter the result set based on Line_off_Date --- which means this is not a WHERE clause issue. Instead, you want to retrieve Line_off_Date values, but substitute #1900-1-1# for any which are Null. If that is correct, do the transformation with a field expression in the SELECT clause.
SELECT Nz(Claims.Line_off_Date, #1900-1-1-#) AS Line_off_Date_adjusted
FROM Claims;

Endeca search query on multiple fields

How to create an Endeca query on combination of multiple fields [just like where clause in sql query]. Suppose we have three fields indexed are -
empId
empName
empGender
Now, I need a query like "where empName like 's%' AND empGender=male"
Thanks.
Firstly,
Checkout Record Filters in the Advanced Development Guide.
If you are trying to use a Record Filter on a property, you will need to enable it explicitly in Developer Studio for that property, while your Dimensions will automatically have the ability to apply a Record Filter. This will help when you have explicit values to filter on, for example empGender.
Your Record Filter can then look as follow:
Nr=AND(empGender:male)
You can further use the Ntk parameter to specify fields to search on so assuming your empName field is enabled for wildcard searching (configure this in Developer Studio) searching this field will look as follow:
Ntk=empName&Ntt=s*
So assuming your properties have been configured correctly, your example above will probably end up looking as follow:
Nr=AND(empGender:male)&Ntk=empName&Ntt=s*
To take this one step further, you can specify Search Filters (ie. Ntk + Ntt parameters) together. I haven't tried this for wildcards so you'll need to confirm that yourself but to combine Search Filters you delimit them with |
Ntk=empName|empId&Ntt=s*|1234*
I suggest you manually build up queries in the Reference Application to confirm you get your expected results and then start to code this up in your application.
radimbe, the problem with record filters for this use case is that they need to be precise. This means you don't get pelling correction, thesaurus expansion, case insensitivity or stemming. It's very unlikely that a user will input precise information like this.
Saraubh, you can do a boolean search to do OR text search queries. You can also use the Endeca Query Language to specify a complex set of boolean logic that goes beyond boolean search and which would incorporate spelling correction, stemming, etc.
In general though, I think for an application like this, you should move away from searching specific individual fields simultaneously and make use of the faceting capabilities of dimensions to guide the user. Additionally, a search box that searches many fields in combination simultaneously in order of importance is really the way to go for a simplified user interface for this sort of application.

Sorting results when autocomplete matches multiple columns in SQL

I've run into an issue with an autocomplete field I'm working on. The field I'm working with is composed of the form "<NAME> (<CODE>)". When a user starts typing in text, I want to display any results that match either NAME or CODE.
For example, if this list contains items and their codes, like "Personal Computer (PC)", then I'd want the list to pop up that row if the user types "P", "PC", "Per", etc.
I've gotten this to work fine in SQLite with a query like this:
SELECT *
FROM table
WHERE name LIKE "?%" or code LIKE "?%"
However, the problem I'm running into now is how to best sort the results that come back from this. For example, If someone enters "PC", I want "Personal Computer (PC)" to be the first result. However, if there's another row (you'll have to bear with me as this is contrived) "PC Case (301)", then there's no simple ordering I can do on the results to ensure that the best match appears first. Ordering by name and code both returns PC Case first.
I want a query where it returns the best match first, rather than items in alphabetical order. Is there such a function I can use in SQLite to get this, or should I return the results and then mess with the order in the code?
If it helps any, I'm using this for FilterQueryProviders on Android.
Yes, you should implement FullTextSearch and the use MATCH in your queries.
Ref: http://dotnetperls.com/sqlite-fts3
This is a long time after the fact, but I've solved my dilemma without having to resort to crazy sorting tactics.
Basically, once an autocomplete gets complex enough, you need to implement your own CursorAdapter (implementing FilterQueryProvider) then override convertToString(). That way, you end up being able to do complex queries via runQuery(), but can then convert it to readable form in convertToString().