I have created one stored procedure which runs on 5000 users in tbluser table with some filter condition in database.There are 4 filtering condition(FC1,FC2,FC3,FC4).Filtering condition has some ListBox and dropdown list of department and countries.I want output as given below:
ID Name StaffNo department Points
1 KK 111 dep1 2
2 NN 222 dep2 1
3 DD 333 dep3 4
I got ID,Name,StaffNo,department in resultset but not points.
points calculation would be based on filtering condition like
if FC1 matched user gained point 1,if both FC1 and FC2 matched user gained 2 point,if both FC1 ,FC2 and FC3 matched user gained 3 point etc.
--in stored procedure i m using dynamic query
DECLARE @SQL VARCHAR(2000)
SET @SQL = 'SELECT U.UserID, U.StaffNo,U.FirstName+'' ''+ U.LastName AS EmployeeName,''?'' AS Points FROM tblUser U '
SET @SQL = @SQL+' WHERE U.Department in (' + @SqlDepartment + ') '
---------------------Update---------------------------------------
IF @SqlLanguage <> ''
SET @SQL = @SQL+' OR U.UserID IN (SELECT UserID FROM Country WHERE LCValues IN ('+ @SqlLanguage +') )'
IF @SqlAreas <> ''
SET @SQL = @SQL+' OR U.UserID IN (SELECT UserID FROM tblAreas WHERE '+@SqlAreas+')'
---------------------Update---------------------------------------
...other filtering condition
EXEC (@SQL)
all filtering condition are implemented with OR logic.
Have you tried implementing a CASE statement to calculate the “Points”?