我创建了一个存储过程来将 IP 地址分成四个不同的列。
ALTER PROCEDURE ipaddress_split
(
@str as varchar(max)
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @query as varchar(max)
SET @query = 'SELECT parsename('+@str+',4) as A
, parsename('+@str+',3) as B
, parsename('+@str+',2) as C
, parsename('+@str+',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')
将参数传递给存储过程的正确方法是什么?