I need to extract everything after the last '=' (http://www.domain.com?query=blablabla - > blablabla) but this query returns the entire strings. Where did I go wrong in here:
SELECT RIGHT(supplier_reference, CHAR_LENGTH(supplier_reference) - SUBSTRING('=', supplier_reference)) FROM ps_product
The SUBSTRING() extracts a substring with a specified length starting from a location in an input string. In this syntax: input_string can be a character, binary, text, ntext, or image expression. start is an integer that specifies the location where the returned substring starts.
Using the charindex function allows you to search for the @ sign and find its starting position and then the substring is used to extract the characters before the @ sign.
select SUBSTRING_INDEX(supplier_reference,'=',-1) from ps_product;
Please use this for further reference.
Try this (it should work if there are multiple '=' characters in the string):
SELECT RIGHT(supplier_reference, (CHARINDEX('=',REVERSE(supplier_reference),0))-1) FROM ps_product
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With