Last post Aug 23, 2017 05:47 AM by Deepak Panchal
Aug 22, 2017 02:48 PM|xyleminc|LINK
I am using Microsoft SQL Server Management Studio 2008 R2
I have a large dataset with a column called charge_band. In this column are data like:
I want to loop through each row and remove the following words:
INS, PRO, MSA, NG, Y02, Y03 and about 30 other 3 letter strings. I know it can be done with loads of replace functions, but is there an easier way?
I also want to replace RL1, RL2 with REP.
So I end up with:
Is this possible?
Aug 22, 2017 03:10 PM|DevNoose|LINK
you can use the TSQL function Replace.
Give a look here
And in case you change your mind and you want to skip the loop...
Aug 22, 2017 03:13 PM|limno|LINK
Aug 23, 2017 04:39 AM|wmec|LINK
Use replace like
Aug 23, 2017 05:47 AM|Deepak Panchal|LINK
I can see that the data in column are entered in a particular format.
it separated with space.
you can try to use Left, Replace, CharIndex and Len function.
SELECT LEFT(string_expression, CHARINDEX(expression_to_find, string_expression) - 1)
for further information you can refer link below.
Removing part of string before and after specific character using Transact-SQL string functions