mercredi 16 septembre 2015

Removing everything after ',' or '.' in a string - SQL Server

Although I checked the answers on StackOverflow, I am not sure hot to apply it on my specific case:

Select s.saleno, s.comments,
case 
    when Charindex('held by', s.comments) > 0 
    then substring(s.comments, Charindex('held by', s.comments)+8,40)
    else null end as TrimmedText,
FROMsales s
JOIN push p 
ON p.saleno = s.saleno
WHERE Charindex('held by', s.comments) > 0;

The issue is that I get result like:

For Company1, due ti
Company1.</p>
Long Company1, is a scan 
Order Company1, originally dated 01/01/2000
Super Company1.</p>
My Company1, due 02/01/2010.</p>

I always want to keep "[...] Company1" and always a dot or a comma appears after this string.

Thank you for the help!

Aucun commentaire:

Enregistrer un commentaire