Grafana - SQL 2014 - MSSQL - How to insert the result of a variable templating in a table

Viewed 130

I want to rework a result of templating variable that looks like this:

'string1','string2','string3'

I try to add few characters like 'test', before every string. In fact if I could just get a way to insert all these strings in a table I would be fine but I fail at this step.. BTW It must work for n string in the result.

Ideal result would be:

select *
    From tbl

returning this (I don't care if column as a title):

colName
'teststring1'
'teststring2'
'teststring3'

but just beeing able to insert it in a table would be nice I'll handle the update of the strings.

1 Answers

If your string is like 'string1,string2,string3' and working with the higher version of SQL Server then you can try the following way.

declare @string as varchar(120) = 'string1,string2,string3'
select 
  'test' +  value 
from string_split (@string, ',')

Here is the live db<>fiddle demo.

Related