-1
我有一些這樣的代碼:分配「並在(‘kuldeep’)username」的變量,並添加到查詢然後執行
declare @Condition nvarchar(50), --value 'and user_name in ('deep')
select * from table where id = 10
10
後,我希望把@Condition
值。如何分配和放置它?
我有一些這樣的代碼:分配「並在(‘kuldeep’)username」的變量,並添加到查詢然後執行
declare @Condition nvarchar(50), --value 'and user_name in ('deep')
select * from table where id = 10
10
後,我希望把@Condition
值。如何分配和放置它?
SET { { @local_variable = expression }
| { @cursor_variable = { @cursor_variable | cursor_name
| { CURSOR [ FORWARD_ONLY | SCROLL ]
[ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
[ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]
[ TYPE_WARNING ]
FOR select_statement
[ FOR { READ ONLY | UPDATE [ OF column_name [ ,...n ] ] }
]
}
} }
}
使用包含SQL作爲查詢的一部分,你需要的EXECUTE
語句的字符串。
DECLARE @Condition NVARCHAR(50) = 'AND user_name IN (''deep'')';
EXECUTE('SELECT * FROM table WHERE id = 10 ' + @Condition);
你有什麼試過的?在問這裏之前,你甚至還查看過BOL TSQL編碼基礎知識嗎? – Raj 2013-02-14 10:23:50