But I want to return only John Smith with no space after John Smith. John Smith is stored inside an employee_name field Is there a way to do this in sql server? There can be more than one instance of the brackets
I tried using the below left(A.[employee_name], CHARINDEX('(', A.[employee_name]) - 1) but it returned following error in SSMS
Invalid length parameter passed to the LEFT or SUBSTRING function. The statement has been terminated.
Since string "indexes" start at "1" in SQL Server, is there a reason why you used "0" for the string starting position or is it just a habit from other languages?
I was trying to get @ahmeds08 to explain by asking him the question about why the substring was started at 0. He didn't go for it.
So... is there a problem with the code? Let's find out. Please run the following against your original table so that we can see what the original problem was. Please post any names exactly as they appear if any are returned by the following code.
SELECT TOP 5
Test = '|'+employee_name+'|'
FROM yourtable
WHERE CHARINDEX('(', employee_name) = 0
;
And, yes... I think you have a problem with your data that you don't know about and we're going to figure it out.