我有程序返回通過與傳遞的參數ID相關聯的行,即1,5,7,9T-SQL的一個問題,當通過CSV串入一個存儲過程
ALTER PROCEDURE [dbo].[get_data]
@MyCodes as varchar(max) = ''
AS
BEGIN
DECLARE @query as nvarchar(max)
set @query = 'SELECT name FROM user WHERE id IN (@p_MyCodes)'
exec SP_EXECUTESQL @query,
N'@p_MyCodes varchar(max)',
@p_MyCodes = @MyCodes
END
該程序生成一個錯誤:將數據類型varchar轉換爲數字時出錯。當我作爲一個參數傳遞例如3,7,5
怎麼了?
檢出:http://www.adathedev.co.uk/2010/02/sql-server-2008-table-valued-parameters.html – AdaTheDev 2010-07-21 12:41:11