sql语句:UPDATE `vol`.`test_number` SET `ProductCode` = '33', `ProductName` = '1', `NumberQty` = 0 WHERE `id` = 3; 用SqlSugar写这个SQL语句
时间: 2023-04-10 16:01:16 浏览: 178
可以使用以下代码:
var db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "your connection string",
DbType = DbType.MySql,
IsAutoCloseConnection = true
});
db.Updateable<TestNumber>()
.SetColumns(t => new TestNumber()
{
ProductCode = "33",
ProductName = "1",
NumberQty = 0
})
.Where(t => t.Id == 3)
.ExecuteCommand();
相关问题
function getPagedList(contractId) { var contractId = body.param.contractId; var sql = ` SELECT a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unitcode unitCode FROM mes214820519.wms_pur_list_214820519 a, mes214820519.wms_product_214820519 b, mes214820519.wms_product_class_214820519 c, mes214820519.wms_unit_code_214820519 d WHERE a.product_id=b.id AND b.product_class_id = c.id AND b.unit_code_id=d.id AND a.contract_id=#{contractId}`; return db.pager(sql, {contractId: contractId}) } 用JavaScript语言修改这段代码
function getPagedList(contractId) {
var sql = `SELECT
a.id,
a.contract_id as contractId,
a.product_id as productId,
a.purchase_num as purchaseNum,
a.purchase_price as purchasePrice,
a.remark,
b.product_name as productName,
b.spec_code as specCode,
c.type_name as typeName,
d.unitcode as unitCode
FROM
mes214820519.wms_pur_list_214820519 a
INNER JOIN mes214820519.wms_product_214820519 b
ON a.product_id = b.id
INNER JOIN mes214820519.wms_product_class_214820519 c
ON b.product_class_id = c.id
INNER JOIN mes214820519.wms_unit_code_214820519 d
ON b.unit_code_id = d.id
WHERE
a.contract_id = :contractId`;
return db.pager(sql, { contractId: contractId });
}
在修改后的代码中,我使用了ES6模板字符串来构建SQL语句,同时使用了INNER JOIN来连接多张表,使代码更加简洁易读。另外,我还使用了命名参数代替了原来的占位符,以提高代码的可读性和可维护性。
org.mozilla.javascript.WrappedException: Wrapped org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [select count(1) from (select a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unit_code unitCode from mes-214820524.wms_pur_list_214820524 a, mes-214820524.wms_product_214820524 b, mes-214820524.wms_product_class_214820524 c, mes-214820524.wms_unit_code_214820524 d where a.product_id=b.id and b.product_class_id = c.id and b.unit_code_id=d.id and a.contract_id= '3b353514235f4a8da8dbcdbcbb5a643e' ) t1]; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-214820524.wms_pur_list_214820524 a, mes-214820524.wms_product_214820524 b,' at line 11 (JavaScriptScriptParse#22)at
这个错误看起来像是一个 SQL 语法错误,可能是因为 SQL 查询语句中的表名或列名有错误,或者缺少了一些关键字。你可以检查一下 SQL 查询语句中的表名和列名是否正确,并且确认缺少的关键字是否正确添加。另外,你也可以将 SQL 查询语句复制到 MySQL 的命令行中执行,看看是否有更详细的错误信息。
阅读全文