if my query is using local params e.g like below
q=\field:test11&
fq=+{!frange cost=200 l=NOW/DAY-10DAYS u=NOW/DAY+1DAY incl=true incu=false}date
How to i specify the must clause ?
So adding + at the beginning of the local param syntax is the correct way?
e.g in the first query, is the leading + correct or not?
+{!frange cost=200 l=NOW/DAY-10DAYS u=NOW/DAY+1DAY incl=true incu=false}date
If not then how do we specify must clause or do we even need must clause here ?
The intent of my query is to find all the documents which have value test11 in field and also the date is within last 10 days.
The query will work as its written if you remove the +. A filter query is always used to filter the current set of returned documents, so it has to match (i.e. it'll always work logically as an AND clause to the original query).
You can probably rewrite that query to just be a range as well:
fq=start_date:[NOW/DAY-10DAYS TO NOW]
Related
I am attempting to use excel INDEX MATCH with the MATCH lookup_array (refdata!$A$2:refdata!$A$150) containing a string e.g. 'AMAZON' which might be part of the MATCH lookup_value ($C2), which is a longer string e.g.''AMZNMKTPLACE AMAZON.CO AMAZON.CO.UK GBR'.
=INDEX(refdata!$A$2:refdata!$C$150,MATCH($C2,refdata!$A$2:refdata!$A$150,0),3)
Is it possible to have the MATCH lookup_array string values set to use wildcards and produce 'AMAZON' from 'AMAZON' and have this then successfully compared to (or found in?) the MATCH lookup_value which would be ''AMZNMKTPLACE AMAZON.CO AMAZON.CO.UK GBR'?
I'm not sure I understand your structure, but this might work:
=INDEX(FILTER(refdata!$A$2:refdata!$C$150,ISNUMBER(FIND(refdata!$A$2:refdata!$A$150,$C2))),,3)
It is looking for AMAZON inside of all strings in Column A and then filtering on it. It will spill if there are multiple matches, so if you don't want that, you can do:
=INDEX(FILTER(refdata!$A$2:refdata!$C$150,ISNUMBER(FIND(refdata!$A$2:refdata!$A$150,C2))),1,3)
Have been trying to understand this for a while ...
How can I specify NOT clause in the following query?
{!field f=schedule op=Intersects}[2016-08-26T12:30:00Z TO 2016-08-26T18:30:00Z]
{!field f=schedule op=Contains}[2016-08-26T12:30:00Z TO 2016-08-26T18:30:00Z]
Like, without LocalParams, we can specify -DateField:[2016-08-26T12:30:00Z TO 2016-08-26T18:30:00Z] to get an equivalent NOT clause. But, I need a NOT Contains Date Range query.
I have tried a few options but I end up getting parsing errors. Surely there must be some obvious way I am missing.
I have built an SSRS report, but am unable to get over one hurdle. It may be simple, I am just unsure of how to solve this.
I have a parameter drop down that allows the user to select one of two options, if they select one option the a portion of the where clause should change, and if the other is chosen it would change again. I will post it below :
If master is chosen :
WHERE myId=1 AND myJournal IS NULL
If Idol is chosen :
WHERE myId=1
So basically just adding a condition and taking a condition based on parameter selection....
This seems very rudimentary, I just can't seem to figure it out.
Thanks for any input
How about
WHERE myId=1 AND (myJournal IS NULL OR #Parameter = 'Idol')
assuming your parameter value get set to Idol of course
The way this works is:
If #Parameter = 'Idol', then the OR clause in the brackets will always be true, regardless of the myJournal value. This reduces the entire WHERE clause to WHERE myId=1 AND true, which is the same as WHERE myId=1.
However if #Parameter = 'master', then the OR clause in the brackets will only be true if myJournal IS NULL as #Parameter = 'Idol' is always false. This means the OR clause can be thought of as equivalent to simply myJournal IS NULL.
This reduces the entire WHERE clause to WHERE myId=1 AND myJournal IS NULL, which is what you are after.
You don't provide any information about the way you want to perform the query.
Do you want to do it with an ajax call?
In this case you should have a selectcombo which will set the needed query string and pass this with an ajax request to the php file that will query the database.
If you want some help we need to have some more information about what you are trying to achieve.
I'm trying to introduce LIKE clause with wildcards in SQL query that runs within Excel 2007, where parameters are taken from specific Excel cells:
SELECT Elen_SalesData_View.ItemCode, Elen_SalesData_View.ItemDescription,
Elen_SalesData_View.ItemValue, Elen_SalesData_View.Quantity,
Elen_SalesData_View.CustomerId, Elen_SalesData_View.CustomerName,
Elen_SalesData_View.SalesInvoiceId, Elen_SalesData_View.EffectiveDate,
Elen_SalesData_View.CountryId
FROM SM_Live.dbo.Elen_SalesData_View Elen_SalesData_View
WHERE (Elen_SalesData_View.EffectiveDate>=? And Elen_SalesData_View.EffectiveDate<=?)
AND (Elen_SalesData_View.CustomerName<>'PROMO')
AND (Elen_SalesData_View.ItemDescription LIKE '%'+?+'%')
The EffectiveDate parameters are running fine and bringing back data as expected. But since I introduced LIKE - query runs, but returns nothing.
It doesn't return any results without wildcards either (full description entered):
(Elen_SalesData_View.ItemDescription LIKE ?)
Is there a restriction to wildcards or LIKE clause? If so, is there a way around it? (I cannot use CONTAINS, as the ItemDescription field is not FULLTEXT)
Have a look at this reference which suggests that % itself is the wildcard character, although it may depend on the dialect of SQL you are using. If this is the case then your LIKE clause will simply be LIKE '%' but untested.
I've just got this to work by using the (Elen_SalesData_View.ItemDescription LIKE ?) syntax then having the cell that contains the parameter value include the wildcard characters. If you don't/can't include the wildcards then create a formula in a separate cell to wrap the value in % characters and use this cell for the parameter value.
Rhys
My query was correct. There was something wrong with the actual spreadsheet. After redoing all from scratch - it worked!
SELECT Elen_SalesData_View.ItemCode, Elen_SalesData_View.ItemDescription,
Elen_SalesData_View.ItemValue, Elen_SalesData_View.Quantity,
Elen_SalesData_View.CustomerId, Elen_SalesData_View.CustomerName,
Elen_SalesData_View.SalesInvoiceId, Elen_SalesData_View.EffectiveDate,
Elen_SalesData_View.CountryId
FROM SM_Live.dbo.Elen_SalesData_View Elen_SalesData_View
WHERE (Elen_SalesData_View.ItemDescription Like '%'+?+'%')
AND (Elen_SalesData_View.EffectiveDate>=?) AND (Elen_SalesData_View.EffectiveDate<=?)
AND (Elen_SalesData_View.CustomerName<>'PROMO')
I'm trying to replace a Keyword Analyser based Lucene.NET index with an SQL Server 2008 R2 based one.
I have a table that contains custom indexed fields that I need to query upon. The value of the index column (see below) is a combination of name/ value pairs of the custom index fields from a series of .NET types - the actual values are pulled from attributes at run time, because the structure is unknown.
I need to be able to search for set name and value pairs, using ANDs and ORs and return the rows where the query matches.
Id Index
====================================================================
1 [Descriptor.Type]=[5][Descriptor.Url]=[/]
2 [Descriptor.Type]=[23][Descriptor.Url]=[/test]
3 [Descriptor.Type]=[25][Descriptor.Alternative]=[hello]
4 [Descriptor.Type]=[26][Descriptor.Alternative]=[hello][Descriptor.FriendlyName]=[this is a test]
A simple query look like this:
select * from Indices where contains ([Index], '[Descriptor.Url]=[/]');
That query will results in the following error:
Msg 7630, Level 15, State 2, Line 1
Syntax error near '[' in the full-text search condition '[Descriptor.Url]=[/]'.
So with that in mind, I altered the data in the Index column to use | instead of [ and ]:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
Now, while that query is now valid, when I run it all rows containing Descriptor.Url and starting with / are returned, instead of the records (exactly one in this case) that exactly matches.
My question is, how can I escape the query to account for the [ and ] and ensure that just the exact matching row is returned?
A more complex query looks a little like this:
select * from Indices where contains ([Index], '[Descriptor.Type]=[12] AND ([Descriptor.Url]=[/] OR [Descriptor.Url]=[/test])');
Thanks,
Kieron
Your main issue is in using a SQL wordbreaker, and the CONTAINS syntax. By default, SQL wordbreakers eliminates punctuation, and normalizes numbers, dates, urls, email addresses, and the like. It also lowercases everything, and stems words.
So, for your input string:
[Descriptor.Type]=[5][Descriptor.Url]=[/]
You would have the following tokens added to the index (along with their positions)
descriptor type nn5 5 descriptor url
(Note: the nn5 is a way to simplify quering numbers and dates given in different formats, the original number is also indexed at the same position)
So, as you can see, the punctutation is not even stored in the full text index, and thus, there is no way to query it using the CONTAINS statement.
So your statement:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
Would actually be normalized down to "descriptor url" by the query generator before submitting it to the full text index, thus the hits on all the entries that have "descriptor" next to "url", excluding punctuation.
What you need is the LIKE statement.
Using "|" as your delimiter causes the contains query to think of OR. Which is why you are getting unexpected results. You should be able to escape the bracket like so:
SELECT * FROM Indices WHERE
contains ([Index], '[[]Descriptor.Type]=[[]12]')