我需要一些與我的SQL邏輯有關的幫助,而且我一直在爲此工作(並研究)這個爲期兩天的工作,並取得了零成功。SQL變量作爲Where子句中的列名稱
我的目標是嘗試將一個變量從一個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正在引用一個帶有字符串的文本框,並將其傳遞給存儲的生成的文本框。 – SyD