我需要一些关于我的 SQL 逻辑的帮助,我已经工作(和研究)了 2 天,但成功率为零。
我的目标是尝试将变量从 ASP 页面传递到存储过程,该存储过程利用该变量作为 where 子句中列名的条件。
例如(我的查询的简化版本):
@strDept nvarchar(10), @strUser nvarchar(30)
-- The asp page will pass f18 to @strDept & 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.
存储过程确实执行,但它不返回任何值,我知道它将 @strDept 视为文字 nvarchar 而不是列名。
所以我想我的问题是,如何让 SQL Server 2005 将我的 @sqlDept 变量视为列名?