I have T-SQL code and am researching how to split
Aruba\abc
Spain\defg
New Zealand\qwerty
Antartica\sporty
Such that the column outputs
abc
defg
qwerty
sporty
So far, I found something like this,
http://www.aspsnippets.com/Articles/Split-function-in-SQL-Server-Example-Function-to-Split-Comma-separated-Delimited-string-in-SQL-Server-2005-2008-and-2012.aspx
But it splits column based on delimiters into new columns.
I wish to keep the information AFTER the delimiter \
Please advise
SELECT RIGHT(ColName , LEN(ColName) - CHARINDEX('\', ColName) )
FROM TABLEName
OR
SELECT PARSENAME(REPLACE(ColName , '\' , '.'),1)
FROM TableName
If you have it as a variable example:
DECLARE @str VARCHAR(50) = 'aruba\abc'
SELECT SUBSTRING(@str,CHARINDEX('\', @str)+1, LEN(@str) - CHARINDEX('\', @str) )
If you have it in a table example:
SELECT SUBSTRING(column1,CHARINDEX('\', column1)+1, LEN(column1) - CHARINDEX('\', column1) )
FROM table1
Here's a sqlfiddle of it working : http://sqlfiddle.com/#!6/85de5/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With