May 1, 2013 at 11:29 pm
Hi guys,
I'm trying to create a function where I can pass a string value that will be used for searching a table column and see if there is match, then replace that string partially when found like below:
Passed string: "John Doe University"
The column values from the table:
SELECT LastName FROM ThisTable
--------------------------------
LastName
---------
Cruz
Patar
Doe
QuiJong
Halal
So if the search is succesful, I'll replace the string with empty string, then the value will be returned as:
John University
Hope it makes sense?
Thanks
May 2, 2013 at 1:09 am
select @SearchString = REPLACE(@SearchString, LastName, '')
FROM ThisTable
select @SearchString
_____________
Code for TallyGenerator
May 2, 2013 at 1:45 am
Not exactly clear on what you are trying to accomplish, but my first instinct is to suggest the STUFF function. You can google it.
May 2, 2013 at 3:20 pm
Thanks guys, Sergiy's answer is exactly what I needed.
Have a nice day.:-)
May 3, 2013 at 3:21 am
Sergiy (5/2/2013)
select @SearchString = REPLACE(@SearchString, LastName, '')FROM ThisTable
select @SearchString
+1 🙂
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply