I have a string like this in a database field:
"Anz Längsteiler":0;"Anz Querteiler":0;"BoxTyp":"M";"Führungslänge":500;"Gewicht":40;
In PowerShell I can do this:
$Hash = @{}
($BoxDS -replace '"','') -split ';' | foreach {
$Val = $_ -split ":" ; $Hash[$Val[0]] = $Val[1]
}
to get an output like this for further use:
PS C:\Windows\System32\WindowsPowerShell\v1.0> $hash
Name Value
---- -----
BoxTyp M
Anz Längsteiler 0
Anz Querteiler 0
Führungslänge 500
Gewicht 40
Now I want to get rid of my PowerShell Script and create an SQL function.
Is there any way I can create a variable with the Name (as you can see in PowerShell output name column) and the value saved in there?
I'm very new to SQL and I read about REPLACE() and SPLIT() but can't really get my head around it. especially when it comes to dynamically creating the variables.
I'm on MS SQL Server 2016