
Construir un Stored procedure con la siguiente función
Publicado por Saul (2 intervenciones) el 06/10/2016 20:31:29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CREATE function dbo.XXXXX (@s varchar(1000), @from_list varchar(100), @to_list varchar(100), @separator char(1) = ';') returns varchar(1000) as
begin
declare @from_len int, @from_CurPos int, @from_PrevPos int
declare @to_len int, @to_CurPos int, @to_PrevPos int
declare @done bit
set @from_len = LEN(@from_list) + 1
set @to_len = LEN(@to_list) + 1
set @from_CurPos = 1
set @to_CurPos = 1
set @from_PrevPos = @from_CurPos
set @to_PrevPos = @to_CurPos
WHILE @from_CurPos < @from_len + 1
BEGIN
set @done = 0
IF SUBSTRING(@from_list + @separator, @from_CurPos, 1) = @separator
BEGIN
WHILE (not @done = 1) and (@to_CurPos < @to_len + 1)
BEGIN
IF SUBSTRING(@to_list + @separator, @to_CurPos, 1) = @separator
BEGIN
set @s = replace(@s, SUBSTRING(@from_list, @from_PrevPos, @from_CurPos - @from_PrevPos), SUBSTRING(@to_list, @to_PrevPos, @to_CurPos - @to_PrevPos))
SET @to_PrevPos = @to_CurPos + 1
set @done = 1
END
SET @to_CurPos = @to_CurPos + 1
END
SET @from_PrevPos = @from_CurPos + 1
END
SET @from_CurPos = @from_CurPos + 1
END
return @s
end
Valora esta pregunta


0