我已經創建了一個存儲過程來將IP地址分成四個不同的列。爲什麼在將參數傳遞給存儲過程時出現錯誤?
ALTER PROCEDURE ipaddress_split
(
@str as varchar(max)
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @query as varchar(max)
SET @query = 'SELECT parsename('[email protected]+',4) as A
, parsename('[email protected]+',3) as B
, parsename('[email protected]+',2) as C
, parsename('[email protected]+',1) as D';
EXEC (@query)
SET NOCOUNT off
END
但是,當我傳遞參數時出現錯誤。
EXEC ipaddress_split @str='191.168.1.1'
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.1'.
我嘗試了所有下面提到的組合,但沒有成功。
exec ipaddress_split '191.168.1.1'
exec ipaddress_split 191.168.1.1
exec ipaddress_split ('191.168.1.1')
將參數傳遞給存儲過程的正確方法是什麼?
是否有任何特別的原因使用動態SQL,特別是在這[可怕的形式](http://stackoverflow.com/search?q=sql+injection)? – GSerg