I have a report with mutiple charts in it that I made. In each chart 5 - 6 Different category groups displayed in a 100% bar chart. I am trying make it so the drill down report can be dynamic but I need use the category group name in my where statement to specify a pass / fail value in that specific column for each category group. This way which ever bar is clicked and which percent in the series is clicked it can be passed as a paramater value to the drill down. I am trying to structure my sql query so the catergory group name can be passed as the column name in the where statement and series pass/fail would be passed as the value in that column like

```
Where [Policy Request] = 'Fail'

```

I'm trying to do this so I don't have to create 5 drill down reports for each chart.  

Both the column I would be specifying and the value in that is once created through a case statement off other values in the query. I have a dataset built that works every time if I set my variables to one of the column names and values that are derived from the table itself, but when I try to declare the variables with the column and value I generated from a case statement I get this message every time

```
Invalid column name 'Fail'.

```

Even though Fail is actually the value I'm looking for not the column. I didn't change the structure of the where statement at all from when I tested it so I'm not sure why its doing that. Also if don't use the variable for the value and just specify it in the query but keep the Column name as a variable it works. Please I'm still a newbie, if there is something I'm missing here or a better way of doing this I'm all ears. Here is my query.

```
DECLARE @MyParm varchar(256) = '[Policy Request]'
DECLARE @Resource varchar(256) = 'Fail'
DECLARE @SQL varchar(max)
SET @SQL = 

'SELECT 
* 
FROM (
SELECT 
summ.ResourceID,
sy.name0,
sy.User_Name0,
Case 
    when Substring(sy.Operating_System_Name_and0,11,7) + '' '' + RTRIM(Substring(sy.Operating_System_Name_and0,34,2)) = ''Windows 10'' Then ''Windows 10''
    when Substring(sy.Operating_System_Name_and0,11,7) + '' '' + RTRIM(Substring(sy.Operating_System_Name_and0,34,3)) = ''Windows 6.1'' Then ''Windows 7''
    Else ''Unknown''
End as ''OS'',
case 
    when summ.LastEvaluationHealthy = 1 then ''Pass''
    when summ.LastEvaluationHealthy = 2 then ''Fail''
    when summ.LastEvaluationHealthy = 3 then ''Unknown''
end as ''Last Evaluation Healthy'',
Case 
    When summ.IsActiveDDR = 1 Then ''Pass''
    When Summ.IsActiveDDR = 0 Then ''Fail''
End as ''Discovery Request'', 
summ.LastDDR,
case 
    when summ.IsActiveHW = 0 then ''Fail''
    when summ.IsActiveHW = 1 then ''Pass''
end as ''Hardware Inventory'',
summ.LastHW,
case 
    when summ.IsActiveSW = 0 then ''Fail''
    when summ.IsActiveSW = 1 then ''Pass''
end as ''Software Inventory'',
summ.LastSW,
case 
    when summ.ISActivePolicyRequest = 0 then ''Fail''
    when summ.ISActivePolicyRequest = 1 then ''Pass''
end as ''Policy Request'',
summ.LastPolicyRequest,
summ.ExpectedNextPolicyRequest,
case 
    when summ.IsActiveStatusMessages = 0 then ''Fail''
    when summ.IsActiveStatusMessages = 1 then ''Pass''
end as ''Status Messages'',
summ.LastStatusMessage ,
case summ.LastEvaluationHealthy 
    when 1 then ''Pass'' else ''Fail'' 
end as ''Client Health Evaluation'',
summ.LastHealthEvaluation,
summ.ClientRemediationSuccess,
case 
    when summ.ClientRemediationSuccess = 1 then ''Pass''
    when summ.ClientRemediationSuccess = 2 then ''Fail''
    else ''''
end as ''ClientRemediationSuccessDescription''

FROM v_CH_ClientSummary summ
Left join v_R_System sy on summ.ResourceID = sy.ResourceID
where 
(sy.Operating_System_Name_and0 like ''Microsoft Windows NT Workstation%'' or sy.Operating_System_Name_and0 is null)
)a

Where ('+@MyParm+') = ('+@Resource+')'

EXEC (@SQL)

```