I have Imported Data Form XLS my CMS. but finally realize that it has wrong data without any Extension at the end of the data, in One of the column of the table, so now I want to change the column data of multiple rows based on specific ID? How to do that using single SQL Query?
I just want to add '.jpg' at the end on these data.
Image
First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.
UPDATE [table] SET [column]=0 WHERE [column] IS NULL; Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and replace them. In the example above it replaces them with 0.
We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.
UPDATE table SET col = new_value WHERE col = old_value AND other_col = some_other_value; UPDATE table SET col = new_value WHERE col = old_value OR other_col = some_other_value; As you can see, you can expand the WHERE clause as much as you'd like in order to filter down the rows for updating to what you need.
UPDATE a
SET a.Imagepath = a.ImagePath + '.jpg'
FROM aspx_itemimages a
WHERE a.ItemId = yourid
Try this one -
UPDATE aspx_itemimages
SET ImagePath = ImagePath + '.jpg'
--WHERE itemid = 755
Try:
UPDATE ImagePath SET ImagePath = ImagePath + '.jpg'
According to your screenshot, some entries actually do end with .jpg
. If you want to append .jpg
only where it is absent, you could use a NOT LIKE
predicate:
UPDATE aspx_itemimages
SET ImagePath = ImagePath + '.jpg'
WHERE ImagePath NOT LIKE '%.jpg'
;
That will also prevent you from adding the extension multiple times if you run the query again accidentally.
The above answers are correct but adding 2 strings returns 0, you will have to concat two strings. here is the example:
UPDATE a
SET a.Imagepath = concat(ImagePath , '.jpg')
FROM aspx_itemimages a
WHERE a.ItemId = yourid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With