Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've attempted to make this question as simple as possible. Listed below is my sql:

SELECT DISTINCT
 fr.EmployeeID
,dsg.SourceKey
FROM Final.FactRegistration fr 
	join Final.FactStudentGroups fsg
		on fr.EmployeeID = fsg.EmployeeID 
			and fr.TermKey = fsg.TermKey
			and fr.VersionKey = fsg.VersionKey
	join Final.DimStudentGroup dsg
		on fsg.StudentGroupSourceKey = dsg.SourceKey
			and dsg.SourceKey = @StudentGroupKey
			
			
WHERE 1=1
AND fr.VersionKey = 1
and fr.EmployeeID


The development of this query will lead me to create a stored procedure. The stored procedure will then be used to populate a SSRS report. Here's the main point to my question. How can the query be written, to allow for an SSRS report to run by not filtering by the student group? However, once the report is run, I still would like to have the ability to filter by student group.

Sample Output Below:

Initial run (All parameters Passed)

EmployeeID | StudentGroup
XXXXXXXXX  | ATHLETE
YYYYYYYYY  | Null
OOOOOOOO   | FinishInFour
ZZZZZZZZ   | Null
PPPPPPPP   | Honor
LLLLLLLL   | Honor
WWWWWWWW   | ATHLETE



Now assume I want to only view Honor students, my output would be:

EmployeeID | StudentGroup
PPPPPPPP   | Honor
LLLLLLLL   | Honor



I need to create a query, stored procedure that will allow for the above output to be accomplished.

Feedback is appreciated, feel free to let me know if you need more information.
Posted

1 solution

Have a read of these links, they should help you out.

Stored Procedure null parameter within where clause: http://dba.stackexchange.com/questions/74461/stored-procedure-null-parameter-within-where-clause[^]
Passing NULL Parameters: http://sqlmag.com/t-sql/passing-null-parameters[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900