I am supposed to remove the following from the address field.
- Replace all words named as ‘Flat’ to empty space, also remove the number that comes along with it.
eg. I have word called as ‘Flat 234 5th Street’.
It should be replaced as 5th Street.
I gave the query as
select
ltrim(rtrim( substring ('Flat 123 5th Street', charindex('Flat ','Flat 123 5th Street') + 5, len ('Flat 123 5th Street'))))
It returned
123 5th Street
Now I have to find whether till the next occurrence of space, I have a numeric value or not.
If Numeric, then remove it, else leave it .
Can anyone help please.
Regards,
Hema
Yes Marc_S, i should have done it (edited).
I can not do in any other language. Supposed to do in T-SQL only.
Hi LittleBobbyTales, Thanks for the Answer.
Actually its not a standard format, I might have only
Flat 123
or Flat 123 5th Street 1st Main Road
or 1st Main Flat 1
There is no rule that we will have 1 numbers or 2 numbers after the word Flat.
There may or may not be numbers at all.
It can be either way.
You could use a scalar-valued function to strip the flat part out. The tricky part is how to check if a word is a number:
@word like '%[^0-9]%'does that by looking for a character that is not 0-9. Full example:Test code:
This prints: