Skip to content
Advertisement

SQL Server substring throws error “multiple results”

I use Microsoft SQL Server 2016.

I have a column that is called Failover and looks like his:

I want that number so I use :

It works fine, but if I want a second column called Account, it crashed with multiple results…

How to fix this ?

Is there a simple way to take the second number and third? I can do it with:

etc etc but it don’t want to repeat myself.

Advertisement

Answer

You can repeat the string operations:

You can also phrase this as a recursive CTE, if you have an indefinite number of values:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement