enter image description hereThis code should return the street address without the street number. These EU address have their street number at the end of the address. I am not sure why the error is happening.
UPDATE STAGING_1_1_FACT_CUSTOMERS_B2B_LGP
SET [StreetAddress] = SUBSTRING([Address], 1, PATINDEX('%[1-9]%', [Address])-1)
FROM [dbo].[STAGING_1_1_FACT_CUSTOMERS_B2B_LGP]
WHERE [Country Code] IN ('NL','DE','LT','AT','BE','ES','DK','IT', 'SE', 'CZ', 'SI', 'SUI', 'EE','PL','HU','LIE','FI','LV')
Identify rows without a number in the address:
To get the entire address when a number doesn't occur, you can use:
Which - finding no number - will add 1 to the length so you can still subtract 1 to get the whole string. That's assuming you want the whole string in that case.
In order to perform the update you're still going to have to prepare for garbage data that you obviously have (or you wouldn't be here) but that you didn't include in your screenshot (also don't post data as screenshots). Given this sample data:
You can run the following update:
Output (which shows what happens to garbage):
Also you don't need the
FROM
line in the update. You're updating the same table.Finally, the requirement makes little sense to me.
StreetAddress
to be everything up to but not including the number?