I have a dataset with housing numbers, street addresses, and zip codes. I am trying to create another column which will include the housing numbers and street addresses. I'm working with about 100,000 datapoints. Most of my addresses are fine, but it appears that TELEGRAPH St has unit numbers at the end, which I do not want. Is there a way I can ask SQL to remove the numbers at the end of all street addresses, ONLY ON TELEGRAPH ST? For instance, most streets are like "Main Street" or "Broadway" but Telegraph has "Telegraph st 400", but I want it just be Telegraph st. I've given part of my code below, but it doesn't seem to work:
Address_Line1=CASE WHEN street1 LIKE 'TELEGRAPH%' THEN (loadd1 + ' ' + REPLACE(street1, '[0-9]', '')) WHEN street1 LIKE 'M %[0-9]%' OR street1 like 'US %[0-9]%' THEN (loadd1 + ' ' + CONCAT(street1, ' HWY')) ELSE loadd1+ ' ' +street1 END
The second portion of my code "WHEN street1 like 'M %[0-9]%'... works just fine, but when I check the output, TELEGRAPH ST still has the unit number at the end.
I've also attempted (very poorly) to create a function, but that didn't work either.
CREATE FUNCTION [dbo].NoNumbers(@x VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
CASE WHEN @x LIKE '%[0-9]%'THEN SUBSTRING(@x,0,CHARINDEX('%[0-9]%',@x)) ELSE @x END
RETURN @x
END
Thanks, your help is much appreciated!
**
**