title: SQL Variables as Column names in Where Clause
body: <p>I need some help with my SQL logic, and I've been working (and researching) this for 2 days now with zero success.</p>
  
  <p>My goal is to try an pass a variable from an ASP page to a stored procedure, which is utilizing the variable as criteria for a column name in the where clause.</p>
  
  <p>So for example (a simplified version of my query):</p>
  
  <pre><code>@strDept nvarchar(10), @strUser nvarchar(30)
  -- The asp page will pass f18 to @strDept &amp; Ted Lee to strUser
  -- f18 is the column name in my database that I need in the where.
  
  select x, y, z from table1 where @strDept in (@strUser)
  -- and this is the select statement, notice the where clause.
  </code></pre>
  
  <p>The stored procedure does execute, but it returns no values and I know its treating the @strDept as a literal nvarchar and not a column name. </p>
  
  <p>So I guess my question is, how do I get SQL Server 2005 to treat my @sqlDept variable as a column name? </p>