Printing records with condition Crystal reports - sql-server

I am using stored procedure in mssql as backend, vb.net as frontend (just info).
There are a lot of records in the database and I am printing in crystal reports.
Now I want to filter the records from crystal report and not by adding a new parameter to procedure or changing database structure or else.
For now,Say there are columns : Name , Amount.
I want to put filter in amount like only display records whose amount above 100 or something. So other records with less than 100 should not be displayed.
This filter will be passed by the user so it'll be random.
I can't find a proper answer on internet. Might be a duplicate question, if so please post the link of the question if it is duplicated.!
Thanx anyways...!

In general the idea is to:
Create the parameter (user choose what will be the input/value) - link
Set filters, what values should be displayed in regards to parameter - link
On right side there is a DataExplorer window, where You need to add a Parameter (define his name, what question will be shown to user and what type the param will be / what values can be set inside).
Once done, You can jump to Data tab of a report, click Interactive Filter and specify which column must fit what condition with what value = Parameter (that one user will enter in Report).
Example: I will create AmountParam, with message "What should be the minimum amount?". Type will be set to Integer. Going to Report->Data->Interactive Filter, choose Amount as a Column, AmountParam as a Parameter and set condition Greater then (>).

Related

How to display a multi-valued parameter onto a SSRS report in a specific way, separated in ranges and/or commas

In SSRS I need to display a multi-valued parameter onto the report in such a way that if values are chosen in sequence they appear as: 1-5, 7, 9-10, 15 and so on. And I have the following values in my drop down list of values: from '0' to '200'.
Thanks in advance for your help.
This is what I have done in SQL so far, so I am thinking to update 'String_To_Use' column so it would display: 0000-1020, 1199-1210, 1260, 1299. Then use this string to display onto the SSRS report. These are the values chosen in SSRS from the drop down box. I don't know yet how I would pass these values to the SQL code yet. Please help with this part as well.
This is the #tempTable1...column 'DPRTMNT' has the values chosen ...Checking_Dept has the value-2 when values in ranges
This is the #tempTable2..I need to update 'String_To_Use' column so it would contain: 0000-1020, 1199-1210, 1260, 1299. #tempTable1 can help to build the logic
replace dsBranchPlant with name of your data set that your using to supply data parameter. And "All" condition is if all params are choosen instead of showing each one. Game this up as an expression and see where you stand.
iif(Parameters!BranchPlant.Count = CountRows("dsBranchPlant"),"ALL",Join(Parameters!BranchPlant.Label,","))

MS ACCESS Report - Using CODE to change a value in a field from an OPTION Group to a different value

I have a report in ACCESS that Is based on a query of a table populated by a form with an Option group. ( to try to explain this better - Table is inspector qualifications, the query pulls all of the qualifications for the inspector, the qualifications are selected via option group on a form that populates the fields of the inspector qualification table.) Of course, the choices are stored as numeric values, "1, 2, 3 or 4" in the table, but 4 actually designates a N/A or NONE. Since everything is already built out this way, I am trying to write a code that will run when the report is generated (or opened,) that will take the "4" value entered (if the field equals that) and change it to a Null value /blank in the report - not in the query or table. I still want this report to generate everything else as is - show all records - just change the value if that particular option is the one shown in that field for that particular record.
Anyone know of a good way to do this? Any help would be GREATLY appreciated!!!!
You would just place an 'IIF' in the query that tests for the value you want to change, then either changes it to something else, or retains the original value. The below will test field 'Nbr1' for the presence of a 4, and if found, change it to 'N/A', otherwise it stays the same.
Note! You will need to change the control source in the report to reflect the name you provide (i.e. 'MyChange') because you can't keep the original name.
SELECT Table1.ID, Table1.EMPID, Table1.TestResult,
IIf([Nbr1]=4,"N/A",[Nbr1]) AS MyChange, Table1.Nbr2
FROM Table1;

Report Builder 3.0 Add Data Elements to an Array

I'm currently working on building a dashboard for some hospital metrics. The state requires that we report median key times. This dashboard will need to display the group median time for each day and the total column will need to display the entire dataset's median.
I'm working with Report Builder 3.0 and SQL Server 2014.
I've built a stored procedure that can calculate all these values accurately but accomplishing the mean this way makes expanding the dataset a bit of a monster when a new field needs to be pulled in.
All the articles (like as this one) I've read for calculating median within Report Builder point to needing to display (or insert and hide) all the data from the dataset. This method seems really hacky to me and is going to make this dashboard an absolute monster to try to manage as it grows.
What I need to know is, is there any way to pass the group values to a custom code function? The report has to have access to the group values at some point or else it wouldn't be able to perform the built in aggregate functions (Sum, First, Last, etc) on these groups. If I can't pass these values as an array to a custom code function, does anybody know how the group aggregate functions are built?
Thanks in advance to any who might have a direction to point me.
You can pass the values from the procedure to a function within SSRS and then have it just display the resulting median. I'll just give you summary to get you started.
Create a hidden parameter that allows multiple values.
Set its available values to pull from the dataset that is populated by your stored procedure.
Also set its default value so that all values are selected by default.
Go to the Code section of the report properties to write your function.
The function will take the parameter as an argument like this Public Function MyFunc(ByVal p1 as object()) as Integer
In the function you can refer to p1.Length and an item in the array like so: p1(i)
In the report you can call the function in an expression like this: =Code.MyFunc(Parameters!p1.Value)
Hope this points you in the right direction.

SSRS parameter returns a data type that is not valid

I got the Tumbleweed badge for this question.... :)
I've moved on a little from the original question but still looking at using internal/hidden parameters, this time passing to another report which runs a stored procedure (which sends an email).
The main report (report A) has a parameter called StudentCourses (originally called ReportParameter1) which I have tried both as Hidden or Internal, and currently has ticked Allow blank value and Allow multiple values.
(Its default value is a field from the result of a query, which shows the courses a student is enrolled on).
Action for my textbox no longer goes to URL (to open PHP form) but now uses Go to report to call report B. Under action options I've added two parameters; StudNetworkID and StudCourses. The number of courses can vary from 2 to 5.
The new report (report B) has two parameters also called StudNetworkID and StudCourses; both are Hidden and StudCourses has ticked Allow blank value. [All parameters are text, btw].
If Report A StudCourses is set to =Parameters!StudentCourses.Value(0) then the first course is shown on Report B. So far so good.
If Report B StudCourses is set to Allow multiple values, then Report B shows #Error and the Warning description given is "[rsInvalidExpressionDataType] The Value expression used in textrun ‘Textbox3.Paragraphs[0].TextRuns[0]’ returned a data type that is not valid."
If Report B StudCourses is set to NOT Allow multiple values and Report A StudCourses value is set to [#StudentCourses] then Report B shows the text "[#StudentCourses]".
If Report B StudCourses is set to Allow multiple values again, then I get the same invalid data type error as before.
Having turned off Allow multiple values on Report B to avoid the #Error issue...
Setting Report A StudCourses to =Parameters!StudentCourses.Value(0) & Parameters!StudentCourses.Value(1) then Report B shows course 1 and course 2 on one line. OK so far.
However, setting Report A StudCourses to =Parameters!StudentCourses.Value(0) & Parameters!StudentCourses.Value(1) & Parameters!StudentCourses.Value(2) gives me a runtime error that the Index was outside the bounds of the array (because there are currently only two courses). On clicking the textbox, Report B just says "The 'StudCourses' parameter is missing a value".
OK...
I turned off Allow multiple values on Report A StudentCourses parameter (the one holding the result from the query) and for the Go to report parameter StudCourses I added the other values, so eventually had value(0) to value(4), the result was interesting. For each parameter value used it gave me a letter from the first course on Report B. Hence when I included up to value(4) it gave me the first five letters of course one!
Yep, ok, this is because it is no longer reading multiple values and so specifying a number just returns the letter from that position.
SO...
How do I allow for up to 5 courses to be passed over???
What follows below is the original question
I have a small report designed in Visual Studio that displays courses that a student is enrolled on. The number of courses can vary from 2 to 5, depending on the student.
Also on the report is a text box, which when clicked will action a url to open a PHP form.
I have worked out how to pass the user id to this PHP form but, if possible, I would also like to pass the course titles.
If I use internal report parameters* I can add these to the url, like this:
="http://myurl/webform.php?param=" & Mid(User!UserID,InStrRev(User!UserID,"\")+1)
& Parameters!ReportParameter1.Value(0)
& Parameters!ReportParameter1.Value(1)
& Parameters!ReportParameter1.Value(2)
& Parameters!ReportParameter1.Value(3)
& Parameters!ReportParameter1.Value(4)
but unfortunately I get the runtime error "The Hyperlink expression for the text box 'Textbox7' contains an error: Index was outside the bounds of the array."
If I just put the first two report parameters it works fine.
I tried using parameter count, e.g. iif(Parameters!ReportParameter1.Count > 2, Parameters!ReportParameter1.Value(2), " "), but I still get the same error.
Please can someone show me how to get around this runtime error, or suggest another way to do this?
Thanks
PS * Report Parameters set up as Text, Allow blank value, Allow multiple values, Internal, Available Values = None, Default Values = Get values from a query; Value field = course title.

Pass field from one dataset to another dataset as parameter In SSRS 2008 R2

I have a scenario where one of my data-set returns multiple records. Now I have implemented grouping in my report so as to display each record from this data set on a different page.
Now I have an another dataset which loads some data using fields from dataset1 as parameter. That means I need to assign the fields from dataset1 to dataset2 as parameter for each record.
For a single record, we can assign the values from dataset1 to a report parameter and then use it for our dataset.
But in this case, parameter always holds the value 1st record and passes it for every page or group.
How can I achieve this?
I had the same problem, where the value was always from the first record in the parent report dataset for each subreport record.
In my case, the resolution was to remove the hidden parameter that I was using in the parent report. The default value I was assigning for that parameter were results from a query.
I then went into the properties of the Subreport, selected Parameters and in the Value dropdown where I originally assigned my parent report parameter, I switched it to the field name of the parent report dataset field so that it would pass the value to my subreport parameter.
Hope this helps.
I may be misunderstanding your question, but I think what you're looking for here is the LookUp() function. This basically fetches data from another dataset, matching on some primary key that you define.
The function has four arguments; the first is the data to match on in the "destination" dataset (I.E. the one that's currently powering your matrix, the second is the data to match on in the "source" dataset (I.E. the one you're fetching the data from). The third is the data you want to fetch, and the fourth is the name of the "source" dataset.
So as an example:
=LookUp(Fields!PrimaryKey.Value, Fields!PrimaryKey.Value, Fields!Data.Value, "DataSet2")
The result of this expression would be for the Report to bring back the data from the field called "Data" in "DataSet2", matching on the values in the fields called "PrimaryKey" in each dataset
Hope that makes sense.
From your explanation, it seems like you want to use a for...next loop but only the first item in Dataset1 is always returned. Did you try to clear the parameter before the loop goes to the next item? Another alternative is to create a Dictionary and add all the items in Dataset1 to it, then loop the Dictionary to get the records for Dataset2, and always clear your parameter before the loop goes to the next item. There should be much better options, but this is what I have for now.
Regards.

Resources