我试图将cvss分数解析为数据表。从看起来像这样的代码开始:AV:N/AC:H/PR:L/UI:R/
我需要制作一个看起来像这样的表
Metric Attribute
1 AV N
2 AC H
3 PR L ...etc
我有一个函数可以创建一个包含每个Metric-Attribute对的列,但是,我不确定如何将它们分成单独的列。有没有人有任何想法?
ALTER FUNCTION [dbo].[Split]
(
@String NVARCHAR(4000),
@Delimiter NCHAR(1)
)
RETURNS TABLE
AS
RETURN
(
WITH Split(stpos,endpos)
AS(
SELECT 0 AS stpos, CHARINDEX(@Delimiter,@String) AS endpos
UNION ALL
SELECT endpos+1, CHARINDEX(@Delimiter,@String,endpos+1)
FROM Split
WHERE endpos > 0
)
SELECT 'Metric:Attribute' = SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0),LEN(@String)+1)-stpos)
FROM Split
)
答案 0 :(得分:0)
在挖掘之后,我能够找到解决方案。
ALTER FUNCTION [dbo].[ParseCvss]
(
@String NVARCHAR(4000)
)
RETURNS TABLE
AS
RETURN
(
WITH Split(stpos,endpos)
AS(
SELECT 0 AS stpos, CHARINDEX('/',@String) AS endpos
UNION ALL
SELECT endpos+1, CHARINDEX('/',@String,endpos+1)
FROM Split
WHERE endpos > 0
)
SELECT 'Metric' = left(SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0),LEN(@String)+1)-stpos), CHARINDEX(':', SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0),LEN(@String)+1)-stpos)) - 1),
'Value' = SUBSTRING(SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0),LEN(@String)+1)-stpos), CHARINDEX(':', SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0), LEN(@String)+1)-stpos)) + 1, Len(SUBSTRING(@String,stpos,COALESCE(NULLIF(endpos,0), LEN(@String)+1)-stpos)))
FROM Split
)