How to reverse a string in SQL Server
sql, sql-server, stored-procedures
Solution
If you have at most four items in the string and none contain periods, then you can use `PARSENAME()`.
select (parsename(replace(@result, ' >> ', '.'), 1) + ' >> ' +
parsename(replace(@result, ' >> ', '.'), 2) + ' >> ' +
parsename(replace(@result, ' >> ', '.'), 3) + ' >> ' +
parsename(replace(@result, ' >> ', '.'), 4)
)
Another option is to split the string and reconstruct it.
Problem
I have a string in SQL stored in `@result` variable of type `Varchar(MAX)` like this: ``` Attributes >> Items >> Category >> Package ``` How can i get the reverse of this without impacting the performance of stored procedure .I want to break the string on the basis of `>>`. ``` Package >> Category >> Items >> Attributes ```