Click here to Skip to main content
15,886,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a column called "Sentence varchar (100)"
it contains the data as
"first name, last name : is Activated on 01/01/2017 "

"first name, last name : is Downloaded on 01/01/2017 "

"first name, last name : is Deleted on 01/01/2017 "

"first name, last name : is Deactivated on 01/01/2017 "

"first name, last name : is Born on 01/01/2017 "



Here I would like to qrite a sql query to show the every string as
"first name, last name : is Activated"

<pre>"first name, last name : is Born"


I want to remove the string from "on date...... so"


Can you please help me with this. how to write a sql server query for this.

What I have tried:

TRIM, SUBSTRING.
I'm unable to remove the string from "on ..." to end.
Posted
Updated 27-Jun-17 9:46am
Comments
ZurdoDev 27-Jun-17 14:48pm    
Use CHARINDEX and find "on " and then go from there. Pretty easy.
Patrice T 27-Jun-17 19:06pm    
Show code.

1 solution

Try this:
SQL
SELECT SUBSTRING(Sentence, 1, PATINDEX('% ON %',Sentence))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900