I have a query as below, that selects Description from table where description contains 'legal:'
At the moment it extracts everything in Description field. What I want to do is only extract 50 characters from 'legal:' keyword on.
SELECT Description
FROM Issues
WHERE
Description like '%legal:%'
Any help appreciated.
MySQL
SELECT SUBSTRING(SUBSTRING_INDEX(Description, 'legal:', -1), 1, 50)
FROM Issues
WHERE Description LIKE '%legal:%'
See a demo
SQL Server
SELECT SUBSTRING(Description, CHARINDEX('legal:', Description) + 6, CHARINDEX('legal:', Description) + 56)
FROM Issues
WHERE Description LIKE '%legal:%'
AND CHARINDEX('legal:', Description) > 0
See a demo
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