以下函数不会在colums中返回任何内容,即使进入调试模式它也会像值一样接... 有人可以帮帮我吗?
显然,表[NewBiz.Labirinto] .dbo.ElencoTipiEsercizio上的select查询工作并返回colums 2 colums: id | DVR 1 | 1,2,3,4 2 | 1,3 4 | 1,2,4,5,6
USE [NuLab]
GO
/****** Object: UserDefinedFunction [dbo].[fun_CSVToTable] Script Date: 29/01/2015 17:17:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Function [dbo].[fun_CSVToTable]
(
@Delimeter varchar(10)
)
RETURNS @RET1 TABLE (id integer, dvr VARCHAR(50))
AS
BEGIN
DECLARE @RET TABLE(id integer, dvr VARCHAR(50))
DECLARE @RET2 TABLE(id integer, dvr VARCHAR(50))
DECLARE @ID integer
DECLARE @LIST varchar(50)
DECLARE @START BIGINT
DECLARE @LASTSTART BIGINT
DECLARE @VAR integer
set @ID = 0
set @VAR = 1
WHILE(@VAR IS NOT NULL)
BEGIN
IF (@ID > (select MAX(id) from [NewBiz.Labirinto].dbo.ElencoTipiEsercizio)) BREAK
set @LIST=(select dvr from [NewBiz.Labirinto].dbo.ElencoTipiEsercizio where [NewBiz.Labirinto].dbo.ElencoTipiEsercizio.id = @ID)
SET @LASTSTART=0
IF LTRIM(RTRIM(@LIST))='' RETURN
SET @START=CHARINDEX(@Delimeter,@LIST,0)
IF @START=0
INSERT INTO @RET(id, dvr) VALUES(@ID, SUBSTRING(@LIST,0,LEN(@LIST)+1))
WHILE(@START >0)
BEGIN
INSERT INTO @RET(id, dvr) VALUES(@ID, SUBSTRING(@LIST,@LASTSTART,@START-@LASTSTART))
SET @LASTSTART=@START+1
SET @START=CHARINDEX(@Delimeter,@LIST,@START+1)
IF(@START=0)
INSERT INTO @RET(id, dvr) VALUES(@ID, SUBSTRING(@LIST,@LASTSTART,LEN(@LIST)+1))
END
INSERT INTO @RET2 SELECT * FROM @RET
SET @ID = (select min(id) from [NewBiz.Labirinto].dbo.ElencoTipiEsercizio where id > @ID)
END
INSERT INTO @RET1 SELECT * FROM @RET2
RETURN
END