how to handle single quote in PATINDEX

I'm trying to parse the names that come in like Doe, John to John Doe and we now have a name like Cox, J'son (which I think is giving me a problem). Is there something I can do to allow quotes in the names?
thanks for your help
RIGHT(dbo.udfTasksPrimaryClosed.ClosedByNameFull,LEN(dbo.udfTasksPrimaryClosed.ClosedByNameFull)-PATINDEX('%,%',dbo.udfTasksPrimaryClosed.ClosedByNameFull)-1) + ' ' +
   SUBSTRING(dbo.udfTasksPrimaryClosed.ClosedByNameFull,1,PATINDEX('%,%',dbo.udfTasksPrimaryClosed.ClosedByNameFull)-1) AS ClosedBy,
   Count(dbo.udfTasksPrimaryClosed.TaskNumber) as ClosedCount,
   AVG(dbo.fn_WorkDays([Created], [Closed])) as ClosedDays

Open in new window

Who is Participating?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I don't see any issue, specifically if you tested that it works.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please confirm that you are using MS SQL Server and not MySQL ...

now, the code you posted in itself is not a problem in regards to the quotes, so it must be some other code.
please post the relevant code.
avoorheisAuthor Commented:
sorry, there was another issue.

However, it is MS SQL and I'm converting a name field from Last, First to First Last (so just the first 2 lines of code, mistakenly copied an additional 2 lines). Seems like a lot to do this, but, I'm a there a better way?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I still don't see the issue...
avoorheisAuthor Commented:
I should have been more's working ok the way it is and does make the swap last/first (there was another issue).
I thought since I had already posted, you might comment on whether the sql that I've used is the best approach for doing what I want.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.