SQL replace any number - mysql

I am in MySql. I have the table named blog and the column photo. I want to make some changes for instance. All the values in that column have that schema:
nunber/text.svg
For instance: 1/marketing.svg
I want to delete the number/
In the example, I want to have: text.svg.
But I want it work with any number, one, two or three digits.
This is what I tried
UPDATE blog
SET photo = REPLACE(photo, '%/', '')

If the string format is consistent, i.e. a number followed by a / and then the text, you can use a combination of substring and locate to update the column.
UPDATE blog
SET photo = SUBSTRING(photo, LOCATE('/',photo)+1)
WHERE LOCATE('/',photo) > 0

Related

Transforming Results from Rows into Columns

I have a data set that contains both common and unique values, which I am attempting to return in a useable format to allow further analyse/work to be taken based on said results.
The desired result would be to have a script that would recognise the common values such as mpan/serial_number/read_at so as to only return a single row, but also to recognise the unique values those being the read_at and identifier.
Currently my script returns a unique row based on the identifier and the value, but I would like to be able to return a unique row for the read_at date for as many identifiers and values as are held. In most cases there are only two identifiers and values, but there could be as many as five.
The issue I have is that when I try to make distinct work, it will only then return the first found result, where I am expecting a pair of results at minimum. I am also unclear as to how I could stop getting a new row and instead create the result as an additional column?
My base script which pulls everything is as below, I have tried a few variances on this, but think this would likely be the best place to start from with regards to any help you may be able to offer?
SELECT *
FROM consumer.stg_d0010_v2_026_027
/*LEFT JOIN consumer.stg_d0010_v2_026_028_029
ON consumer.stg_d0010_v2_026_028_029.file_identifier = consumer.stg_d0010_v2_026_027.file_identifier
AND consumer.stg_d0010_v2_026_028_029.mpan = consumer.stg_d0010_v2_026_027.mpan*/
LEFT JOIN consumer.stg_d0010_v2_026_028_030_032
ON consumer.stg_d0010_v2_026_028_030_032.file_identifier = consumer.stg_d0010_v2_026_027.file_identifier
AND consumer.stg_d0010_v2_026_028_030_032.mpan = consumer.stg_d0010_v2_026_027.mpan
LEFT JOIN consumer.stg_d0010_v2_026_028_030_033
ON consumer.stg_d0010_v2_026_028_030_033.file_identifier = consumer.stg_d0010_v2_026_027.file_identifier
AND consumer.stg_d0010_v2_026_028_030_033.mpan = consumer.stg_d0010_v2_026_027.mpan
where consumer.stg_d0010_v2_026_028_030_032.read_At > '2022-10-01'
and consumer.stg_d0010_v2_026_027.mpan in (
)
Example dataset in image below.
enter image description here
And desired outcome
enter image description here
The issue I have is that when I try to make distinct work, it will only then return the first found result, where I am expecting a pair of results at minimum. I am also unclear as to how I could stop getting a new row and instead create the result as an additional column?

unable to concatenate the first 3 characters of one list field with another list field in shareoint infopath form

I am trying to concatenate a designator field that combines my autonumbered index field with the first 3 characters of my group field
Index field automatically incremented current Highest index +1
I have another field that needs to Join the first 3 characters of my group field with the index field
example
Index: 1008
Group: ABM Support
Designator: (Desired result) 1008ABM
I get an error in the InfoPath form when I try to use:
concat((LEFT(Group,3), Index)
Expected value type: )
Actual value: ,
concat((LEFT(../my:Group,3)-->,<-- ../my:Index)
I have two Items I need to combine as a Designator for a SharePoint list. I have been able to auto increment the Index number, and I need to combine the index and first 3 characters of the group field to create the designator. I realize now I cannot use a concatenate string i.e. concatenate(LEFT(Group,3), Index). The problem lies that there are no common consistent characters to set a substring statement up. I was thinking to Add a default space at the beginning of the input and use that but not really sure how to go about that. Please advise if that would work and how to go about it.
Solution:
Concat(Substring(1,3),Index)

How to update a new column with only a piece of text from another column - MySQL

I am trying to pull only part of the value from one column: "CI_Support_Remarks" to update another column "Asset_Number" in my table "CI_Information". If the data is currently stored as:
"Asset#: 33800000125Primary support:Persons nameSecondary support....ect"
How do I only pull the number following "Asset#:" and nothing else to update the Asset Number column. I am only trying to update the Asset column and not affect the CI_Support_Remarks column.
As a note all the asset numbers are the same length and stored in the same format.
Thanks
Just use substr():
update t
set asset_number = substr(CI_Support_Remarks, 9, 11);

concatenate using Allen Browne's example

I am using the 'concatenate related' module created by Allen Browne to concatenate rows into a single field. At first I had a lookup field at the table level and later realized this is not a good approach. So I deleted the lookup column and instead made a query for selecting values from the lookup table on my form and then store that value as a number in the table.
The module works when I concatenate the values but it is listing the number (id) whereas I would like the actual description (i.e. 1 = Red, 2 = Blue, etc.)
My SQL query code is as follows:
SELECT DISTINCT
tblCompany.JobID,
concatrelated("type","tblMonitor","JobID = " & [jobID]) AS Expr1
FROM tblCompany;
I would like "type" to display the description instead of the number. I know if I store my lookup value as text instead of number it will work. But for efficiency it seems the number should be stored in the table and then query for the description when you need it....or maybe text is fine??? I'm guessing I would need to add the lookup table to this query. I have tried but with no luck so far.
Create a query which joins tblMonitor with the table which holds the type description field. Then use that query with ConcatRelated.
ConcatRelated("type_descriptn","YourQuery","JobID = " & [jobID])

MySQL - Populate a field based on part of another field

I have a table where one column, named Description, has a variety of information all crammed together. Part of that information is an abbreviation for a vehicle maker. For example, the Description column could read "6cylM.Benz32zy,.026L"
I want to populate a new Vehicle column with Mercedes Benz wherever the Description column contains M.Benz somewhere inside. The key word there is "somewhere"; the abbreviated vehicle name could be anywhere in the description field.
So far I have the following code. However, MySQL tells me it can't find the %M.Benz% column. I'm not trying to look for a column named %M.Benz%, I'm trying to find TEXT that is %M.Benz%.
UPDATE tbl_arcore_repuestos
SET Vehicle = `Mercedes Benz`
WHERE Description LIKE `%M.Benz%`;
Any ideas? Most of the other solutions on StackOverflow to similar questions rely on the sought-after text being in a fixed position (like at the beginning of the string or separated by a consistent character). The text I'm looking for could be ANYWHERE in the Description column.
Have you missed the quotes or used backticks instead of quotes?
UPDATE tbl_arcore_repuestos SET Vehicle = 'Mercedes Benz' WHERE Description LIKE '%M.Benz%';