select stuff((select ','+data_name from DataConf where uid in (30024,40026,40027,40028,40029) for xml path('')),1,1,'')
sql复制代码
select stuff((select ','+data_name from DataConf where uid in (select * from dbo.GetInStr(verify_conf5)) for xml path('')),1,1,''),* from ProcessConf where type_id=1 and uid=40240
sql复制代码
USE [KH_04]
GO
/****** Object: UserDefinedFunction [dbo].[GetInStr] Script Date: 2024/4/1 14:38:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[GetInStr]
(@SourceStr varchar(2000))--源字符串
-- =============================================
-- Author: <lupeng>
-- Create date: <2024-04-01 09:35>
-- Description: <将以逗号间隔的uid字串返回成表,便于查联表查询>
-- https://www.553668.com/manong/1309449.html
-- =============================================
RETURNS @table table(list varchar(50) )
AS
BEGIN
-- select @sourcestr = replace(@sourcestr,';',',')
-- select @sourcestr = replace(@sourcestr,' ',',')
--declare @OutStr varchar(200)
if charindex(',',@sourcestr)>0
begin
declare @i int
declare @n int
set @i=1
while charindex(',',@sourcestr,@i)>0
begin
set @n=charindex(',',@sourcestr,@i)
insert into @table values(substring(@sourcestr,@i, @n-@i) )
set @i=@n+1
end
insert into @table values(substring(@sourcestr,@i,len(@sourcestr)-@i+1))
end else insert into @table values(@sourcestr)
delete from @table where isnull(list,'') = ''
return
END
sql复制代码
USE [KH_04]
GO
/****** Object: UserDefinedFunction [dbo].[Split] Script Date: 2024/4/1 14:39:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[Split](@separator VARCHAR(64)=',',@string NVARCHAR(MAX))
RETURNS @ResultTab TABLE (
Id INT ,
Res NVARCHAR(500)
)
AS
-- =============================================
-- Author: <lupeng>
-- Create date: <2024-04-01 09:35>
-- Description: <将以逗号间隔的uid字串返回成表,便于查联表查询>
-- https://www.cnblogs.com/hualiuliu/p/11457325.html
-- =============================================
BEGIN
DECLARE @Num INT
IF(@string IS NOT NULL AND @string <> '' AND LEN(@string)>0)
BEGIN
IF(CHARINDEX(@separator,@string)>0) --判断要截取的字符是否存在
BEGIN
SET @Num=0
WHILE (CHARINDEX(@separator,@string)>0) --如果要截取的字符存在,就继续循环
BEGIN
SET @Num=@Num+1
INSERT INTO @ResultTab(Id,Res) --截取字符串,插入表变量
SELECT @Num,LEFT(@string,CHARINDEX(@separator,@string)-1)
--把已经截取并插入的字符串删除
SET @string=STUFF(@string,1,CHARINDEX(@separator,@string)-1+LEN(@separator),'')
END
--如果最后一个截取的字符串为空,那就不插入了
--例如:'123,456,789,' 这样的字符串最后剩下的就是空字符串了
IF(@string IS NOT NULL AND @string <> '')
BEGIN
INSERT INTO @ResultTab(Id,Res)
SELECT @Num+1,@string
END
END
ELSE
BEGIN
INSERT INTO @ResultTab(Id,Res) --截取字符串,插入表变量
SELECT 1,@string
END
END
ELSE
BEGIN
DELETE FROM @ResultTab
END
RETURN
END