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.
Related
I have designed a function that works with an SSRS report. I have a drop down parameter that lists multiple items and only one can be selected. This drop down gets its data from a query/data set, and I added one line of data that says 'All' in it. So the dropdown will look like this:
Item1
Item2
Item3
All
And then in the function, I make one small change in the where clause:
...where (#parameterName = 'All' or table.name = #parameterName)
The problem with this is that table.name has about 50000 rows of data. When the user selects 'All' in the drop down, I would have thought that since the first statement in brackets is true, and that the next statement (after the 'or') should not even be executed. But it causes the query to run for 5-20 minutes and still does not produce any result after that long. If I simply change the where clause to
...where (#parameterName = 'All')
The function runs in less than a second, if the user still selects 'All' from the drop down.
I implement a similar concept with another filter but I guess because the table that that parameter uses is much smaller (about 90 rows), so it doesn't take long.
Is there basically a way to have an optional parameter that is not expensive to calculate?
EDIT: I will add that the parameter is declared as nvarchar(max). Will changing this to something smaller help the query?
What you have there is a catch-all query. Consider adding OPTION (RECOMPILE) to the end of your statement. This'll force the engine to recreate the plan each time it runs the query, meaning it won't use poor choices based on a previous run where your variable has a value like 'Item1'.
I have a SSRS report. there is a long SQL query on the main query, in the last SELECT I want to filter the results with WHERE expression, the filter should be with a multi value parameter.
I set the parameter in this way:
Create a new Dataset with a query.
Add a new parameter to the Parameters folder (with name NewParam).
Check the "Allow multiple values" checkbox.
Add the parameter to the "Main Query" and set the value with this expression:
=Join(Parameters!NewParam.Value,",")
At the end of the Main Query I filter the results:
select *
from #FinalStatusTbl
where Test_Number in (#NewParam)
order by Priority
The problem is:
On the report when I choose one value from the list I got expected results, but If I choose multi values the results are empty (not got an error.)
Do you have any idea why?
(When I try this: where Test_Number in ('Test 1', 'Test 2') it works well).
When you create a dataset with a sql query, multi valued parameters work with the in(#ParamName) without any changes.
Replace your =Join(Parameters!NewParam.Value,",") with just =Parameters!NewParam.Value and you should be fine.
That said, the reason you see people using that join expression is because sometimes your query will slow down considerably if your parameter has a lot of potential selections and you data is reasonably large. What is done here is to combine the join expression with a string splitting function in the dataset that converts the resulting Value1,Value2,Value3 string value in a table that can be used in the query via inner join.
This is also a requirement if passing multiple values as a parameter to a stored procedure, as you can't use the in(#ParamName) syntax.
You could try taking the parameter out of the where clause and use the parameter in the filters section of the dataset properties.
This will effectively shift the filtering from the SQL to SSRS.
What you need to do is split your string in the database. What is being passed to your query is 'Test 1, Test 2' as a complete string, NOT 'Test 1' and 'Test 2'. This is why a single value works, and multiple values do not.
Here is a really good link on how to split strings, in preparation for your scenario. The function I most often use is the CTE example, which returns a table of my split strings. Then I change my SQL query to use IN on the returned table.
In your example, you will want to write WHERE Test_Number IN (SELECT Item FROM dbo.ufn_SplitStrings(#NewParam) , where ufn_SplitString is the function you create from the link previously mentioned.
This is what I did and it works well to me. You can try it also.
=sum(if(Fields!Business_Code.Value = "PH"
and (Fields!Vendor_Code.Value = "5563"
and Fields!Vendor_Code.Value = "5564"
and Fields!Vendor_Code.Value = "5565"
and Fields!Vendor_Code.Value = "5551")
, Fields!TDY_Ordered_Value.Value , nothing ))
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]
Im making a report that has a parameter
DateFrom:
Date To:
Handled: Successful or Unsuccessful
GroupName:
AgentNamme:
What I want to do is if I selected in Handle 'Unsuccessful' the GroupName will be disabled. I tried looking for answers on the net but failed.
Hi I think you can achieve this using Optional Parameter feature of SSRS.
or you can change the data set in such a way. you can edit the query and check there.
Example- Optional Parameter
You can't disable a parameter in SSRS. You have to provide a placeholder value to it instead, usually a null value.
The available values for GroupName should be based on a query to get all of the possible group values, unioned with a null value for N/A. When Handled = Unsuccessful, the only possible value for GroupName should be N/A.
Since its impossible to disable a parameter I just query a default value if Hanled=Unsuccessful.
My question is how can I set the default values for a certain index in variable length array column. I am trying to set the value of one of the positions to default to string 'false'.
Reason being is I want to be able to have a where clause on a query to filter items where the position value is 'true' (I am setting specific ones to true manually) but without having the rest of my data default to false on that value my query is not fetching any data.
If this is confusing let me know and I will try to clear it up..Thanks in advance
Generally, a column default is for the whole column - for the whole array in your case.
You would have to write a trigger for that. But you may not need any of this. I quote your question:
... but without having the rest of my data default to false on that value
my query is not fetching any data.
You can probably avoid this if you query with:
(arr[5] = 'true') IS NOT TRUE
(which includes all cases there the flag is anything but 'true', even NULL) instead of:
arr[5] <> 'true'
And if you need this query fast you can support it with a partial index:
CREATE INDEX tbl_special_idx ON tbl (col1) -- potentially more columns
WHERE (arr[5] = 'true') IS NOT TRUE;
The important part is the WHERE clause. You can use columns in place of col1 that might cover the whole query (especially in v9.2) or that have additional conditions in your query ...