Reputation: 163
I have a column which should contain the names of cities, but some users made a mistake an entered the full address. Now I want to delete the extra part of that and just keep the first part.
For example I have:
1- Paris,lab lab, shop shop, no 23
2- London,street 1,street 2,No 11
3- New York,street 1,street 2,No 11
But what i want is :
1-Paris
2-London
3-New York
but I just want Paris and I like to delete the rest. The city
column is in Persian Language and as you might know, Persian is written from right to left.
Thank you for your help
Upvotes: 0
Views: 467
Reputation: 1409
This worked for me:
SELECT
LTRIM(REVERSE(SUBSTRING(REVERSE([name]),1, CHARINDEX('٬', REVERSE('٬' + [name])) - 1)))
FROM dbo.City
You can create similar queries for UPDATE if you want to change the data.
To clarify: If you have following cities in the dbo.City table:
Then it returns
Update your post with an example of what you expect in case I didn't understand you correctly.
Upvotes: 2