Remove first character if quotation mark - mysql

I have the following two strings:
/Volumes/ISCSIRAID_04/PORTAL_ASSETS/NOVIYDISK_FOURLIONS_TRAILER
"/Volumes/newfile.mov
How would I remove the first character of the string, if it = "?
I was thinking:
UPDATE users SET data = SUBSTR(data, 2);
But then this will always do a replace, instead of only when it's a ".

Just add a where clause:
UPDATE users SET data = SUBSTR(data, 2) WHERE data LIKE '"%';

Related

mysql update json attribute and another column in one query

I need to update a json value in a column as well as update another column in the same query.
Something like this:
UPDATE fixtures
SET jsonResults = '{}',
JSON_SET(jsonFixture, '$.time_status', '0')
WHERE intRefID = 88961323;
How can I accomplish this?
JSON_SET() returns a JSON document value, but an UPDATE statement needs a series of assignment expressions:
UPDATE fixtures
SET jsonResults = '{}',
jsonFixture = JSON_SET(jsonFixture, '$.time_status', '0')
WHERE intRefID = 88961323;
This replaces jsonFixture with the result of JSON_SET(), after setting a field within that document.
Compare with an UPDATE like this:
UPDATE mytable
SET i = i + 1
WHERE ...
It takes the value of i, adds 1, and then uses the result of that addition expression to replace i.

How to update a column only when last word of string matches a letter

I want to update columns(HostActvTyp and HostPrvTyp) when (HostCd) column last name is matching with last word of the string is "R"
example string for host column "NXVR','REACTIVE', so the last word is R so we have to update to Reactive when it's N' to 'NEW' example "XVDN"
enter image description here
seems you are looking for left or substr()
update tablename
set ActTyp = 'INDEPENDENT'
where ActvTyp = left(your_value,1 )
https://www.db-fiddle.com/f/bG4jZfnWksjc315eGTuG2k/1
UPDATE tablename
SET ActTyp = 'INDEPENDENT'
WHERE 'I' = RIGHT(ActvTyp, 1)
Or if there is a space separator
UPDATE tablename
SET ActTyp = 'INDEPENDENT'
WHERE ' I' = RIGHT(ActvTyp, 2)

SQL error with variable assignment, concat, and right

I'm trying to generate an ID by concatenating bits from a few cells in a MySQL table. I want t0 get rid of - and : and only have digits in the ID. I get a syntax error with the following:
update scan_data
set #scanDate1 = replace(scanDate,'-','')
set #scanTime1 = replace(scanTime,'-','')
scanID = concat(right(scanContent,2),right(#scanDate1,2),right(#scanTime1,2))
What do I need to change?
Try this
update scan_data set scanID = concat(right(scanContent, 2),
right(replace(scanDate,'-',''), 2),
right(replace(scanTime,'-',''), 2)
);

SQL CONCAT String + Column in WHERE clause

I got a numeric value in Foo.A and it has its equivalent in Bar but with a string prefix ("Z"). I'm trying to append the "Z" to the Bar.A col value. I also tried with CONCAT but without any success. This following codes returns "Unknown column Z".
UPDATE Foo, Bar
SET Foo.B = Bar.B
WHERE Foo.A = Z + Bar.A
For example 14 (Foo.A) = Z14 (Bar.A).
If your syntax works, then it is likely you are using MySQL. In any case, the problem is that you need quotes around string constants. So try this:
UPDATE Foo join
Bar
on Foo.A = concat('Z', Bar.A)
SET Foo.B = Bar.B;
You should always use single quotes for string and date constants, regardless of the database. That is the ANSI standard and it reduced the possibility of error.
You are missing the single quotes around Z i.e. your code should be:
UPDATE Foo, Bar
SET Foo.B = Bar.B
WHERE Foo.A = CONCAT('Z', Bar.A);
Actually I found it. I missed the "" in CONCAT.
This is working:
UPDATE Foo, Bar
SET Foo.B = Bar.B
WHERE Foo.A = CONCAT("Z", Bar.A)
Where is you join statement you are using table B in the update statement and table A in the where condition. This is not gonna work

Mysql search multipule value from comma seperated string

Here I want to search like
I have a string say $var = "1,3,5,7"
And
in my table say table student there is a column say column_abc
And this column contain values like
column_abc
2,3,45,6
1,3,4,5,8
3,4,6,9
1,5,10,13,34
I want to search $var against that column column_abc
can anybody help me
In result I want rows which contain any number present in $var
Am I right that you want to search in the table students for the value of column_abc? In that case you can use the following PHP code:
$result = mysql_query("SELECT * FROM `student` WHERE `column_abc` = '" . mysql_real_escape_string($var) . "'");
Hope this helped.
This solution may work for you ...
where column_abc regexp '(^|,)$var($|,)'
If $var is equal to 2, then it will find it twice in the below scenario:
2,3,45,6,12
1,2,3,4,5,8
3,4,6,9
1,5,10,13,34
EDIT: Just re-read your question, and you were looking for an entire string of numbers, and not just one ....
declare #search int(10)
declare #Search2 int(10)
Set #Search = '1,2,3,4'
Set #Search2 = #Search+'%'
select * from student where _abc like #Search2