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
Related
THE CODE I AM WORKING IS:
UPDATE `tab_base_asset`
INNER JOIN `vw_calcula_taxa_adm_ymf_acumulada_3`
ON `tab_base_asset`.`codigo_fundo` = `vw_calcula_taxa_adm_ymf_acumulada_3`.`codigo_fundo`
SET `tab_base_asset`.`RECEITA_ADM_YMF` = (`tab_base_asset`.`saldo_bruto_cdc`/`vw_calcula_taxa_adm_ymf_acumulada_3`.`saldo_bruto_cdc`) * `vw_calcula_taxa_adm_ymf_acumulada_3`.`receita_YMF_ACUM`,
`tab_base_asset`.`RECEITA_REBATE` = (`tab_base_asset`.`saldo_bruto_cdc`/`vw_calcula_taxa_adm_ymf_acumulada_3`.`saldo_bruto_cdc`) * `vw_calcula_taxa_adm_ymf_acumulada_3`.`Rebate_acumulado`
WHERE `tab_base_asset`.`data` = (SELECT `tab_aux_datas_base_unica`.`data_final` FROM `tab_aux_datas_base_unica`);
I would like to make the column receita_adm_ymf to become 0 for values which are less then 0.
I have got some syntax errors when using IF on My SQL Workbench 5.2 I also tried Case but I am not sure where to place it in the code.
Use the GREATEST() function to assign the max of the expression value and zero.
SET `tab_base_asset`.`RECEITA_ADM_YMF` = GREATEST(0, (`tab_base_asset`.`saldo_bruto_cdc`/`vw_calcula_taxa_adm_ymf_acumulada_3`.`saldo_bruto_cdc`) * `vw_calcula_taxa_adm_ymf_acumulada_3`.`receita_YMF_ACUM`),
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.
Hi all i have been writing a query and it is driving me crazy because it is giving me syntax error for ''
my query is
UPDATE test1 SET result =
CASE WHEN formula = "p1+p2" THEN 2
the error is here on line 2
any help is highly appreciated.
A case should always have an end:
UPDATE test1
SET result = (CASE WHEN formula = 'p1+p2' THEN 2 END);
This sets result to either "2" or NULL. You probably want:
UPDATE test1
SET result = 2
WHERE formula = 'p1+p2';
As a general rule, use single quotes for string constants. This is the ANSI standard.
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)
);
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 '"%';