Home removing certain part of string from column in table
Reply: 1

removing certain part of string from column in table

mHelpMe
1#
mHelpMe Published in 2018-02-13 14:45:33Z

I have a table which contains a text column called 'Note'.

This column contains null values and some string values. The update query below was run on the table when it shouldn't have been.

update tblExample set Note = Note + ' USD Temp influx'

So the rows with null's in them haven't changed but the other rows have.

I want to remove this text from the field and leave any other text already in there remaining. What is the best way to do this?

Is it something like below but in an update query? Not sure how this should be written?

select replace(Note, ' USD Temp influx', '') from tblExample? 

update

sorry should have said the column is a nvarchar type

lad2025
2#
lad2025 Reply to 2018-02-13 15:03:58Z

You could use:

UPDATE tblExample
SET Note = replace(Note, ' USD Temp influx', '')
WHERE Note LIKE '% USD Temp influx'; 
-- it will replace all occurences in string (not only the last one)

or more secure way:

UPDATE tblExample
SET Note = LEFT(Note, LEN(Note) - 16)
WHERE Note LIKE '% USD Temp influx';

Rextester Demo

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34204 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO