
SEPARAR CAMPO STRING A FILAS
Publicado por Gray (6 intervenciones) el 20/08/2015 01:10:54
Hola buena tarde,
Estoy tratando de separar un campo a filas, ejemplo:
Esta es mi tabla A
PopId Specification
406575 00001B |00017TK|00021AL|00022BA|00031B |00035Z |00037A |00067Z
406942 00001B |00017TK|00021AL|00022BA|00031B |00035Z |00037A |00067Z |00072A
408410 00001B |00017TU|00021AL|00022AZ|00031B |00035Z |00037C |00067Z |00072A
Quiero que me inserte el valor de Specificacion
tabla B
PopId Specification
406575 00001B
406575 00017TK
406575 00022BA
406575 00031B
.........N
creo que es algo así, alguna idea??
CREATE FUNCTION [dbo].[Template_Musys]
(
@string NVARCHAR(MAX),
@delimiter varchar('|')
)
RETURNS @output TABLE(Specification NVARCHAR(MAX)
)
BEGIN
DECLARE @start INT, @end INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
WHILE @start < LEN(@string) + 1 BEGIN
IF @end = 0
SET @end = LEN(@string) + 1
INSERT INTO @output (Specification)
VALUES(SUBSTRING(@string, @start, @end - @start))
SET @start = @end + 1
SET @end = CHARINDEX(@delimiter, @string, @start)
END
RETURN
END
Estoy tratando de separar un campo a filas, ejemplo:
Esta es mi tabla A
PopId Specification
406575 00001B |00017TK|00021AL|00022BA|00031B |00035Z |00037A |00067Z
406942 00001B |00017TK|00021AL|00022BA|00031B |00035Z |00037A |00067Z |00072A
408410 00001B |00017TU|00021AL|00022AZ|00031B |00035Z |00037C |00067Z |00072A
Quiero que me inserte el valor de Specificacion
tabla B
PopId Specification
406575 00001B
406575 00017TK
406575 00022BA
406575 00031B
.........N
creo que es algo así, alguna idea??
CREATE FUNCTION [dbo].[Template_Musys]
(
@string NVARCHAR(MAX),
@delimiter varchar('|')
)
RETURNS @output TABLE(Specification NVARCHAR(MAX)
)
BEGIN
DECLARE @start INT, @end INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @string)
WHILE @start < LEN(@string) + 1 BEGIN
IF @end = 0
SET @end = LEN(@string) + 1
INSERT INTO @output (Specification)
VALUES(SUBSTRING(@string, @start, @end - @start))
SET @start = @end + 1
SET @end = CHARINDEX(@delimiter, @string, @start)
END
RETURN
END
Valora esta pregunta


0