asked on
CREATE FUNCTION dbo.Split3 ( @strString varchar(4000))
RETURNS @Result TABLE(Value BIGINT)
AS
BEGIN
DECLARE @x XML
SELECT @x = CAST('<A>'+ REPLACE(@strString,'/','</A><A>')+ '</A>' AS XML)
INSERT INTO @Result
SELECT t.value('.', 'int') AS inVal
FROM @x.nodes('/A') AS x(t)
RETURN
END
GO
select [GEOMapCode],SFS from [dbo].[MapData]
;with cte as (SELECT GeoMapCode, dbo.Split3('.'/ 'VARCHAR(200)') AS series
FROM (SELECT [GEOMapCode], CAST ('<M>' + REPLACE(series, '/', '</M><M>') + '</M>' AS XML) AS String
FROM dbo.MAPDATA) AS A
CROSS APPLY String.nodes ('/M') AS Split(a))
select row_number() over(order by [GEOMapCode], series) as id, [GEOMapCode], series
from cte
ORDER BY 1,2
ASKER
--Do the work
with tmp(GeoMapCode, DataItem, Data) as (
select GeoMapCode
, LEFT(SFS, CHARINDEX('/',SFS+'/')-1)
, STUFF(SFS, 1, CHARINDEX('/',SFS+'/'), '')
from dbo.MapData t1
union all
select GeoMapCode
, LEFT(Data, CHARINDEX('/',Data+'/')-1)
, STUFF(Data, 1, CHARINDEX('/',Data+'/'), '')
from tmp
where Data > ''
)
select GeoMapCode, DataItem
from tmp
order by GeoMapCode
ASKER
Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
ASKER