USE [riskmain]
GO
/****** Object: UserDefinedFunction [dbo].[fnSplit] Script Date: 2020/7/23 12:05:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: 将字符串拆分为表
-- Modify: liuli 2013-9-28 9:49:40 判断为空情况
-- =============================================
CREATE FUNCTION [dbo].[fnSplit]
(
@string VARCHAR(max),
@split VARCHAR(2)
)
RETURNS @t TABLE(col VARCHAR(MAX))
AS
BEGIN
WHILE (CHARINDEX(@split, @string) <> 0)
BEGIN
INSERT @t
(
col
)
VALUES
(
SUBSTRING(@string, 1, CHARINDEX(@split, @string) -1)
)
SET @string = STUFF(@string, 1, CHARINDEX(@split, @string), '')
END
IF (@string <> '')
BEGIN
INSERT @t
(
col
)
VALUES
(
@string
)
END
RETURN
END
GO
存储过程调用该函数:
ALTER PROCEDURE [Base].[prVehicleShareMointDel]
@ModifiedUserID int
,@IDs nvarchar(max)
,@O_RETURN INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
UPDATE [Base].[VehicleShareMoint]
SET
ModifiedUserID=@ModifiedUserID
,[ModifiedTime]=GETDATE()
,[IsValid]=0
WHERE EXISTS
(
SELECT 1
from dbo.fnSplit(@IDs,',') AS B
WHERE B.col=ID/*ID代表[Base].[VehicleShareMoint]中的ID*/
@IDs:该值为前端传过来的值
);
IF @@ROWCOUNT>0
BEGIN
SET @O_RETURN=1;
END
ELSE
BEGIN
SET @O_RETURN=0;
END
END;
GO