December 12, 2008 at 1:48 pm
this is the code we have and just want to know if there is any better way of writing it
CASEWHEN PATINDEX ('% %', REVERSE(lastName)) = 0 THEN lastName
ELSELTRIM(RTRIM(
RIGHT(
LTRIM(RTRIM(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
.
.
.
, '@', '')
, 'Mr', '')
, '(U)', '')
, '(A)', '')
.
.
.
))
, PATINDEX ('% %'
, REVERSE(
LTRIM(RTRIM(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
.
.
.
, '@', '')
, 'Mr', '')
, '(U)', '')
, '(A)', '')
.
.
.
))
)
)
)
))
END AS LName,
December 12, 2008 at 2:13 pm
Since you're doing string-cleaning, you might care to take a look at using the Regex functionality. In 2000, you can tap into Regular Expressions using custom Regex Extended procedures; there are copies of those in the scripts area on here ( I think they are in the DBA toolkit for 2000 if that is still up there).
It tends to make things much clearer and cleaner (usually turning that into a single, much cleaner function call).
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply