If you are using SQL Server, you can use a combination of PATINDEX and STUFF :
SELECT *, STUFF(T.address, 1, PATINDEX('%[Az]%', T.address) - 1, '') FROM
PATINDEX will find the index of the first letter in your string and STUFF used to trim everything from the beginning to this index.
This conclusion:
id address No column name) --------------------------------------------- 1 23 Bridge road Bridge road 3 7 Bridge road Bridge road 5 9 Bridge road Bridge road 2 14 Kennington street Kennington street 4 12 Oxford street Oxford street
I also noticed that you have a different order in the expected output. If it was conceived. You need to use ROW_NUMBER:
SELECT ROW_NUMBER() OVER(ORDER BY STUFF(T.address, 1, PATINDEX('%[Az]%', T.address) - 1, ''), T.id) AS ID, T.address FROM
This request will generate a new identifier for each row.
Result:
id address ------------------------ 1 23 Bridge road 2 7 Bridge road 3 9 Bridge road 4 14 Kennington street 5 12 Oxford street
In any case, this is a pretty hacky decision.
I suggest you keep your address in separate columns, such as street name, zip code, house number, home letter (optional), city, etc. This will be a much better approach.
Evaldas Buinauskas
source share