CAML Query builder not working for And/Or combination in SharePoint 2010 - caml

I am using CAML builder in SharePoint 2010 visual web part. But it is not working for And/Or combination.
Ex: I need to get the records from list based on Status=published or (Status=Draft and createdBy=currently logged in user) and AppName=SharePoint.
CAML query is not working for the above scenario. But for part of the above statement(below) is working.
Status=published or (Status=Draft and createdBy=currently logged in user)
Please let us know the solution which will work for And/Or combination in CAML query.
Thanks in Advance,
Krishna Rao Maturi.

Work!!!
You may use 2 conditions only, to use more, you need use combination of conditions, example:
<And>
Condition A
<or>
Condition B
Condition C
<or>
</And>
This equal this: (ConditionA && (ConditionB || ConditionC))

Related

How to write a calculated field using Microsoft Access expression builder?

I'm trying to write a query that will calculate "Shares short" divided by "Shares floating". See my table below. I've tried the following expression, but I just get a big fat error.
Expr1: [Shares]![SharesType]="Shares short"/[Shares]![SharesType]="Shares floating"
I've also tried looking at Microsoft's expression tutorials (and the linked tutorials) but they're too general.
I find expression builder more confusing than helpful and don't use it.
If you are trying to do an aggregate query, click the Sigma icon on query designer tab and build in the design grid. Switch to SQL view to view statement which should be like:
SELECT CompanyID, Sum(IIf([SharesType]="s",[Shares],Null))/Sum(IIf([SharesType]="f",[Shares],Null)) AS Expr1
FROM Shares
GROUP BY CompanyID;
This worked.
SELECT Companies.CompanyName, Sum(IIf([SharesType]="Shares short",[Shares],Null))/Sum(IIf([SharesType]="Shares floating",[Shares],Null)) AS [Short as % of Float]
FROM Companies INNER JOIN Shares ON Companies.CompanyID = Shares.[Company ID]
GROUP BY Companies.CompanyName;
So my report now looks like this.

Now you're thinking with parameters; Having a NOT list as a parameter option (report builder 3.0)

I have been super impressed with the way you guys think about parameters in SSRS. You can make them do all sorts of interesting things. I have a report where I want two parameter options reflected in my SQL query, option one is as list of numbers for a certain field. This is easily done via
WHERE [DDI] in #DDI
Setting up the parameter DDI to include the full list of numbers. The point I'm struggling is with the counter case. In essence I need the query to become
WHERE [DDI] not in #DDI
If the second option is picked. I think the best way to solve this is with nested parameters but I can't think with portals sorry parameters in the correct way to figure this out.
TLDR : I want a parameter solution where user can pick between 2 options the first gives them a curated list in a particular field and the second gives everything except that curated list.
You could create a drop down parameter with Include (YES), Exclude (NO) wording. Then in your stored procedure it could filter based on the value passed
WHERE (( #Include = 'YES' AND [DDI] in #DDI) OR (#Include = 'NO' AND [DDI] NOT IN #DDI))
``

GroupBy Query over YRBSS Socrata API

Need help to build a sample query to get YRBSS 2015 statistics for questioncode H43 and grouped by race. I was following docs1 and doc2 and was able to get complete data for 2015 by following query:
https://chronicdata.cdc.gov/resource/6ay3-nik2.json?$where=(StratificationType='State' OR StratificationType='National')&year=2015&questioncode=H43
However $group=race is not working(is this possible? please advice). Any help would be much appreciated.
This question might not look technical but since support center suggests to post questions on stack overflow, I'm posting it here
What was your query using the $group=race? You will need to have a select statement and some aggregation function (e.g., count, sum, etc.).
Guessing that you want counts of individual responses by race, this statement will work:
https://chronicdata.cdc.gov/resource/6ay3-nik2.json?$select=race,count(race)&$where=(StratificationType=%27State%27%20OR%20StratificationType=%27National%27)&questioncode=H43&year=2015&$group=race
It's preceded by $select=race,count(race) to provide counts.

SSRS: Filter 1 field based on 2 possible values in another field

I don't if I'm being a knucklehead, but I've searched considerably and tried several options: can't make it happen. Here is the issue.
I have the following Data Query:
First of all, sorry it's French. Secondly, as you see, the fields are "File number", the "Year" and the "Number of distinct patients".
Wanted result: I want to filter for Case numbers who appear both at 2015 and 2016.
As you see, certain patients showed up several years in a row. However, I want to find out how many showed up in 2015 AND 2016 only (not 2014, etc.) (so a total of 2 visits for the 2 years combined). So solely filtering in my Data Query on 2015 and 2016, doesn't do the job, since it fails to exclude the patients that only showed up once. Furthermore, filtering on 2015 and 2016, and then Count(Fields!File_number.Value)=2 wouldn't work since it fails to exclude the patients that might have been here in 2014.
I have tried several Boolean expressions, but as soon as I include 2 years in my filter, it blanks my tablix out. (Understandibly cause I tell it that Fields!Year.Value must be equal to 2015 and 2016 simultaneously).
So I tried bypassing it by telling it that and did the following:
Expression:
=IIF(Lookup(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset")=2015 AND Lookup(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset")=2016, True, False)
It works for 1 year only: as soon as I add 2015 either by and "AND" or by adding an additionnal filter, mytable goes blank.
Any suggestions? Thanks!
Yeah, this isn't an easy thing to solve, you aren't being a knucklehead :) You are correct about the double boolean expressions in the query and the two combined lookups won't work either. In the case of a lookup, LOOKUP returns the first match in a dataset, so every time, both of those looksups are going to return the first value.
There is another function called LookupSet which does return ALL matches from a query though. It should be possible to create an ugly expression around this function to test specifically whether the string 2015 and 2016 both appear in the results with something like:
=Join(LookupSet(Fields!FileNumber.Value, Fields!FileNumber.Value, Fields!Year.Value, "Dataset"),",")
and then substring searching for both "2015" and "2016" (I'll let you fiddle with that part)

SSRS: How to select two or more values from a long filtered multiple selection list with different search strings

Let's consider a multiple selection parameter on a report: Employee
This parameter has a lot of possible values. Initially nothing is shown on the list and there is a textfield search parameter associated, that updates the Employee selection list with top n matches for the searched string.
If the entered search query is John Doe we can imagine that now the selection list shows:
John Doe
...
Xavier John Doesson
Now I can select as many items as I want from this filtered list, but if I want to select both John Doe and Alicia Keys happens the following:
First when I enter the search string "John Doe" the selection list gets populated accordingly
I select John Doe - OK
I enter search string "Alicia Keys", the selection list gets populated also
Selection of John Doe is gone - I want to be able to select both Alicia and John at the same time, but I don't want to go through a thousands of names long selection list
Update:
Forgot to mention that we have an OLAP cube in the background with dimension 'Employee'. This dimension is used as the source of the parameter and the param dataset uses MDX to fetch the values, therefore the SQL solution cannot be applied here.
The current solution creates an custom set with MDX Filter and Head functions and then this set is used in the ROWS-part of the MDX query.
Here is how the set created:
SET setEmployees AS {
HEAD(
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch,1 >= 1 )
)
,100)
}
Basically the problem with this solution is that how do you add multiple search strings to the instr function
Is there a common solution to this kind of situation? Am I approaching the problem from wrong direction?
What you could do is make the search parameter more flexible, so you can handle input such as:
John OR Jane
If "OR" queries are more common than "AND" queries you could support it with queries such as:
John Jane
Note that this may throw people off, because the search features they're used to (such as Google search) typically tend interpret multiple words in the "AND" sense.
Anyhow, the tricky bit of course is the SQL behind the Employee data set. This should use the search parameter in a more flexible way. You haven't specified how that's currently working, but I imagine you may be using something like:
WHERE Employee.FullName LIKE '%' + #SearchParameter + '%'
You would need to extend that to support "OR" queries. There's a whole range of solutions for that, from quick 'n dirty handmade SQL (e.g. string split combined with WHERE...IN) to full-text querying. Choose a solution that's best for your situation.
If you have a fixed number of search terms than you can do something like the following.
FILTER( [Employees].[Employees].ALLMEMBERS,
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch1,1 >= 1) OR
INSTR([Employees].[Employees].CURRENTMEMBER.Name,#EmployeeSearch2,1 >= 1)
)
Even if you can do that, I do not recommend it. You don't have the luxury to index Analysis Services like you do SQL. A better possible approach would be to query your data warehouse for the employees and return the appropriate keys, and then filter by those keys in your MDX statement.