带SQL替换功能的通配符?

时间:2019-06-10 06:21:24

标签: sql sql-server-2014

我有一个值如下的变量

DECLARE @var VARCHAR(MAX) = 'ROOT(10) AS TEN, ROOT(50) AS FIFTY, ROOT(70) AS SEVENTY'

我只想从变量中获取'TEN,FIFTY,SEVENTY'

以下是我尝试过的内容:

REPLACE(@var, 'ROOT(%) AS', '')

任何人都可以给我一个关于如何获得所需输出的想法吗?

2 个答案:

答案 0 :(得分:0)

DECLARE @var varchar(max) = 'ROOT(10) AS TEN, ROOT(50) AS FIFTY, ROOT(70) AS SEVENTY'

select replace(replace(replace(@var,'ROOT(10) AS ',''),'ROOT(50) AS ',''),'ROOT(70) AS ','')

答案 1 :(得分:0)

使用递归CTE尝试以下解决方案:

{
 "status": 1,
 "message": "data",
 "comment": [
   {
    "id": "1",
    "comment": "abc",
    "reply":
    [
      {
        "id1": 1,
        "table1ID": 1,
        "reply": "efg"
    }

  ]
},
 {
    "id": "1",
    "comment": "abc",
    "reply":
    [

    {
        "id1": 2,
        "table1ID": 1,
        "reply": "mnr"
    }
  ]
},
{
    "id": "2",
    "comment": "xyz",
    "reply":
    [
      {
        "id1": 3,
        "table1ID": 2,
        "reply": "slq"
     }
    ]
  }
 ]
}