62,046
社区成员
发帖
与我相关
我的任务
分享
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <zhoulizuo>
-- Create date: <2008-9-12>
-- Description: <功能:实现split功能的函数:删除时,传递的参数是多个要删除的主键 >
-- =============================================
ALTER function [dbo].[PrimaryKey_split]
(
@inputstr varchar(8000),
@seprator nvarchar(10)
)
returns @temp table (Pri_Key nvarchar(200))
as
begin
declare @i int
declare @EveryKeyLen int--每个主键的长度
--每个主键的长度
declare @EveryKeyValue nvarchar(200)
set @inputstr = rtrim(ltrim(@inputstr))
set @i = charindex(@seprator, @inputstr)
while @i >= 1
begin
set @EveryKeyValue =left(@inputstr, @i -1)
if(len(@EveryKeyValue)>0)
insert @temp values(@EveryKeyValue)
set @inputstr = substring(@inputstr,@i+1, len(@inputstr) - @i)
set @i = charindex(@seprator, @inputstr)
end
if @inputstr <> '\' and len(@inputstr)>0
insert @temp values(@inputstr)
return
end
--调用
--select * from PrimaryKey_split ('ff;-1;0;0;0;',';')