How do I update column's values from another column? - go-gorm

In short, I'm trying to do the following using the gorm package.
UPDATE TableName t SET t.col1 = t.col2;
Is there a way to do where gorm only does 1 query?

You can do this using Gorm methods
db.Table("TableName t").Update("t.col1", gorm.Expr("t.col2"))
Source: https://github.com/jinzhu/gorm/issues/1947#issuecomment-397376537

Related

how to update in-memory table dynamically using dolphindb database

Is there any way to update an in-memory table dynamically using dolphindb? I need more suggestions to write a dynamic update function. Now I can only get the table name returned. I tried several methods to update the data for a specified table but failed.
Script 1:
table1=table(1..6 as id,2..7 as v, 3..8 as v1, 4..9 as v2, 5..10 as v3 );
share table1 as t1;
tableName ="t1";
update!(tableName, `v, 666);
Error report:
Read only object or object without ownership can't be applied to mutable function update!
Script 2:
updateSql = "update t1 set v = 999;";
parseExpr(updateSql).eval;
Error report:
Invalid expression: update t1 set v=999;
What's the correct syntax to update a specified table?
Use DolphinDB's function update! to update the columns in an existing table:
update!(table, colNames, newValues, [filter])
Here table is a DolphinDB table. The error occurs because your script defines the table type to be of STRING type. Use objByName to change it:
update!(objByName(tableName), `v, 666);
If you want to know more about dynamical expression generation, meta programming will be of help.

how to update the multiple rows at a time in aspnetboilerplate?

I want to execute the SQL clause like:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Because I want to update multiple rows in database. But I don't know how to implement this.
I have found the solution. Using the extension method GetDbContext of Repository to get the DbContext, then using the DbContext.Database.ExecuteSqlCommandAsync to execute raw SQL.

Update field values of table with field values that is in query

UPDATE Tbl, Qry SET Tbl.Submit_Date = [Qry]![FirstOfTIMESTAMP]
WHERE (((Tbl.Info_ID)=[Qry]![INFO_ID]));
I want to update Tbl.Submit_Date with values from [Qry]![FirstOfTIMESTAMP] where both of their info_id are equal.
I get an error saying Operation must have an updateable query. I am using MSAccess. Any help is greatly appreciated.
As you learned, in MS Access queries must be updateable in order to be used in UPDATE queries. As a workaround consider converting your SQL aggregation to domain aggregation with DMin() assuming FirstOfTIMESTAMP is the Min() aggregation from a source table
UPDATE Tbl
SET Tbl.Submit_Date = DMin("TIMESTAMP","SrcTable","Info_ID=" & Tbl.[INFO_ID])

SQL Update a field by removing a part of it

In my work, I am stuck with a SQL problem.
I have a field in one of my table which contains strings of the form "%_abc". I want to update this column by removing "_abc" at end of every entry. Is there a nice way to get this done using SQL?
Thanks,
Anil.
update table1 set field1 = substr(field,1,length(field1)-4) where ...
HTH
If your database is ANSI SQL-92 compliant, you can use:
UPDATE myTable SET myColumn = TRIM(trailing '_abc' FROM myColumn);

vb.net access query for updating

is d query rite ?
q = "update FIRSTBBA WHERE FBBANAME<>"" ORDER BY FBBANAME"
Need to update a table in ascending order
This query is not complete. You can use inner SQL statement based on your requirement and update the table based on that.
You're not assigning a value to FIRSTBBA.
Also, not sure what database you're using but I don't think SQL server allows an order by clause in an update statement. you would have to refer to a post like this one: How to update and order by using ms-sql