0

I'd like a bit of help please with an SQL command

I have some text and I need to add and an extension to the end of the string on anything.

I've tried this but it doesn't work the way I want it to:

UPDATE table1 SET column1  = '%TEST%' WHERE 'column1' LIKE '%TEST%' + '.exe'

as the output I'd like is

TEST1.exe
TEST2.exe
TEST3.exe
Nick
  • 138,499
  • 22
  • 57
  • 95
  • Possible duplicate of [How can I append a string to an existing field in MySQL?](https://stackoverflow.com/questions/3765631/how-can-i-append-a-string-to-an-existing-field-in-mysql) – ambianBeing Sep 27 '19 at 21:43

1 Answers1

2

You need to use CONCAT to add to the string, and your UPDATE syntax isn't quite right. This should work:

UPDATE table1
SET column1 = CONCAT(column1, '.exe')
WHERE column1 LIKE '%TEST%'
Nick
  • 138,499
  • 22
  • 57
  • 95
  • looking into the mysql databse its added it outside the [ ] is there anyway to get it inside the [ ] ["TEST1"].exe – Daniel Peters Sep 27 '19 at 22:16
  • @DanielPeters can you show me some sample data - the data in your question doesn't have any `[]` around it... – Nick Sep 28 '19 at 00:39
  • ["http:\/\/URL1\/1"] – Daniel Peters Sep 28 '19 at 10:56
  • @DanielPeters I presume you want to end up with `["http://URL1/1.exe"]`? What version of MySQL are you running? – Nick Sep 28 '19 at 12:16
  • msql 5.7.26 the url displays like that in phpmyadmin i think it would need to end up as ["http:\/\/URL1\/1.exe"] – Daniel Peters Sep 28 '19 at 12:36
  • Are all the names in that general form i.e. `["` followed by name followed by `"]`? – Nick Sep 28 '19 at 12:38
  • yes ["http:\/\/URL 1\/1"]["http:\/\/URL 2\/2"] also where there are two urls in that column how to i get the .exe to apply to url 1 and not url 2 – Daniel Peters Sep 28 '19 at 13:39
  • @DanielPeters take a look at [this](https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=b01694e1ee7bd608229440d331090b9b) I think it should do what you want? – Nick Sep 28 '19 at 22:17