Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim string based on characters

I have strings like

WebApp - 10148

Smart - App - 1458

Expected Result

WebApp

Smart - App

I want to trim the characters from - to numbers from right.

I have tried the below query and the result is this

select LEFT(app+' - ', CHARINDEX(' - ',app+' - ')-1) from repository

WebApp
Smart

Can anyone assist me to sort this?

like image 500
Michael Avatar asked Feb 22 '26 09:02

Michael


1 Answers

Try this:

reverse(right(reverse(@string), len(@string) - charindex('-',reverse(@string),1)));
like image 78
Rahul Tripathi Avatar answered Feb 25 '26 08:02

Rahul Tripathi