【发布时间】:2013-08-21 14:25:03
【问题描述】:
我需要一些关于我的 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 变量视为列名?
【问题讨论】:
-
所以
@strUser是一个以逗号分隔的整数列表? -
不,@struser 正在引用一个带有字符串的文本框,该文本框正在传递给存储的生产者。
标签: sql sql-server tsql