Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Command to replace a substring within a text column
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Web
Miscellaneous
Thread ID:
01371396
Message ID:
01371404
Views:
15
This message has been marked as a message which has helped to the initial question of the thread.
>Hello all,
>
>I need to write a SQL UPDATE statement that will replace a substring within a column with a blank. The substring to replace can be any value so I cannot search on this, but I do know that the value to replace is between known values. The column is a varchar that has descriptive values in it as follows:
>
>'Buy xxxxxx vSymbol @.....Sell yyyyyy vSymbol @....'
>
>The 'Buy' and 'Sell' are constant. The vSymbol is variable but will be the same in the column and there is another column in the table that has this value so it can be referenced in the update statement. The xxxxxx and yyyyyy are variable and might not have the same value but these are to be replaced with a blank (along with the vSymbol). The '@' sign is also constant. I want the end result column to be as follows:
>
>'Buy @...... Sell @'
>
>TIA

Look at CHARINDEX(), REPLACE() and STUFF() functions in Help.

Try to experiment with different input strings until you get it right.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform