mousemat24
asked on
How to get some text based on a char
Hi there
Hope you can help me?
I have a string like this
Fred Blog (Feb 2009)
Can someone please write a function that will get me ALL the text BEFORE the '('
i.e.
Fred Blog
thanks
Hope you can help me?
I have a string like this
Fred Blog (Feb 2009)
Can someone please write a function that will get me ALL the text BEFORE the '('
i.e.
Fred Blog
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here you go.
Assume you have a table named "MyTable"
Create one column named "INUPT" for your input string and one column named "NAME" for the trimmed name.
Then, run this procedure on the table:
UPDATE MyTable SET NAME = LEFT(INPUT,LEN(INPUT)-CHAR INDEX('(', INPUT))
This should put the trimmed name in the NAME column.
Assume you have a table named "MyTable"
Create one column named "INUPT" for your input string and one column named "NAME" for the trimmed name.
Then, run this procedure on the table:
UPDATE MyTable SET NAME = LEFT(INPUT,LEN(INPUT)-CHAR
This should put the trimmed name in the NAME column.
You have answers above, but here are a few notes:
Your substring will end up with an extraneous space; therefore, you may need to RTRIM the text if there is a space before '(' as in your example.
If the text you pass the function does not contain a '(', you will get an error; therefore, you may want to add an IF/CASE statement OR do this:
Your substring will end up with an extraneous space; therefore, you may need to RTRIM the text if there is a space before '(' as in your example.
If the text you pass the function does not contain a '(', you will get an error; therefore, you may want to add an IF/CASE statement OR do this:
SUBSTRING(@Text, 1, CHARINDEX('(', @Text+'(') - 1)
ASKER
thanks