The end-user must be able to search on EITHER the student's username or the student's ID (2 report parameters: @StudentADAccount [varchar] and @StudentReference [int] respectively). Most of the remaining datasets use the resulting @StudentReference number in their "where" clause. A student always has a "Student Reference" but not necessarily a student AD account (enquired/applied only).
So following the above, I end up with:
Then I want the ID parameter ("@StudentReference") to populate itself if it is left blank when the report is executed. So my first dataset has to include the Username check as well (…WHERE StudentID=@StudentReference OR StudentName=@StudentADAccount). And according to other web articles on this matter, I have to change the order of my parameters (I will be checking "Student Username" first as "Student Reference" must be calculated and not blank/null):
So I tried setting the "Available Values" as suggested by Stack Overflow to gets its value based on the first parameter but ended up with an error going on about "forward dependencies".
This is obviously going to error, so continuing on their solution, setting the "Available Values – Specify values" to
=IIF(LTrim(Parameters!StudentADAccount.Value)="", Parameters!StudentReference.Value, First(Fields!S_STUDENTREFERENCE.Value, "StudentDetails"))
- =IIF(LTrim(Parameters!StudentADAccount.Value)="", Parameters!StudentReference.Value, First(Fields!S_STUDENTREFERENCE.Value, "StudentDetails"))
Apparently not because "fields cannot be used in report parameter expressions". I tried this with "Default values" and got the same problems. Note: before you try, "Variable values cannot be used in report parameter expressions" either.
I'm using an Oracle/PLSQL database for this so whether you're using T-SQL or MySQL you'll need to use the appropriate variable references (eg. T-SQL is @localvariable, Oracle is :localvariable). I need to change it to a conditional query with the OR statement below:
Lets take the following query as an example:
SELECT table1.studentID , table2.studentUsername FROM table1, table2 WHERE table1.studentID = capd_table2.studentID AND ( table1.studentID = :StudentReference OR table2.studentUsername = :StudentADAccount )
- SELECT table1.studentID
- , table2.studentUsername
- FROM table1,
- table2
- WHERE table1.studentID = capd_table2.studentID
- AND ( table1.studentID = :StudentReference
- OR table2.studentUsername = :StudentADAccount )
Now searching on the ID parameter ("@StudentReference") still works but when I type a Username ("@StudentADAccount"), it populates only the first dataset with results; the remaining datasets that need to use the ID parameter all returned zero rows.
- So one workaround exists where if I combined all 10 dataset queries into 1 mega dataset query, problem solved…
- Another workaround exists where if I added the OR part to all my datasets (so where each one says if studentreference is blank then compare to studentadaccount)…
There must be a solution that executes a query at report execution time and populates/assigns the local variable ID (@StudentReference) everytime. So after an hour or so I came across "Cascading Parameters" (http://technet.microsoft.com/en-us/library/dd255197.aspx). Maybe the answer could be in that mess of a Microsoft article but this I can already do and it didn't quite do what I wanted.
I ran out of time (all MORNING!) so I went with solution #2 (above) and added the OR clause to all my dataset queries and joined the table containing the other parameter (@StudentADAccount) in each dataset query, which slowed it down a little but the requirement was met. If your end-users complain, do what Microsoft suggests and throw more memory at the SQL Server.
The remaining issue is what if the user leaves both fields blank? This would return all users who don't have an AD account. Using the revisited solution below -> Just leave the "allow blank" option in the parameter properties unchecked
SSRS Report Revisted:
Had an issue where SSRS report parameters were not resetting to blank after the report was run. End-Users were putting different values in both fields and getting twice as many rows back. I modified the report leaving only one open parameter, the OR clause just compares against the same parameter.
So for example: Instead of
... (student_accounts.student_name=@StudentName or student_accounts.student_id=@StudentID)
- ...
- (student_accounts.student_name=@StudentName or student_accounts.student_id=@StudentID)
... (student_accounts.student_name=@SearchWord OR student_accounts.student_id=@SearchWord)
- ...
- (student_accounts.student_name=@SearchWord OR student_accounts.student_id=@SearchWord)
Sorry only a workaround at the moment!
I don't think I can recommend Microsoft's SQL Server Reporting Services as a replacement for website applications. We only did it because we have more staff trained in SSRS than in bespoke third-party software and the ability to support/develop outweighed the cons.