use Dynamics go --海关单位转库存单位 ------------------------------------------ --创建表及其相关字段 drop table Jimmy_UnitConversionTest go CREATE TABLE Jimmy_UnitConversionTest ( ItemId varchar(41) default('') not null, InventQty decimal(24,4) default(0) not null, InventUnitid varchar(10) default('') not null, CSMQty decimal(24,4) default(0) not null, CSMUnitId varchar(10) default('') not null, factor decimal(24,12) default(0) not null ) insert into Jimmy_UnitConversionTest(ItemId,InventQty) values('Col-1100',10) update a set InventUnitid = b.unitid from Jimmy_UnitConversionTest a join InventTableModule b on a.itemid = b.itemid where b.moduletype = 0 GO select * from Jimmy_UnitConversionTest where InventUnitid = '' update a set a.factor = 1 from Jimmy_UnitConversionTest a where a.CSMUnitId = a.InventUnitid and factor = 0 GO select * from Jimmy_UnitConversionTest where factor = 0 GO -- 更新与库存单位的换算 update a set a.factor = b.factor from Jimmy_UnitConversionTest a join unitconvert b on a.itemid = b.itemid and a.CsmUnitId = b.fromunit and a.Inventunitid = b.tounit and a.factor = 0 GO -- 反向更新 update a set a.factor = 1 / b.factor from Jimmy_UnitConversionTest a join unitconvert b on a.itemid = b.itemid and a.CSMUnitId = b.tounit and a.Inventunitid = b.fromunit and a.factor = 0 GO -- 系统不存在的换算率: select * from Jimmy_UnitConversionTest where factor = 0 go -- 找不到的直接用1做换算率 update a set a.InventQty = case when factor <> 0 then (1 / factor) * CSMQty when factor = 0 then (1 / 1) * CSMQty end from Jimmy_UnitConversionTest a GO
SQL statement for Unit conversion
原创
©著作权归作者所有:来自51CTO博客作者fandyx的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
使用Statement执行sql语句
Demo2.javapackage com.cn.statement;import java.sql.Connection;im
Statement sql java mysql -
java中的SQL注入(Statement的SQL注入)
java中,查询MySQL数据库中的数据,在使用Statement对象时,存在SQL注入问题
java开发 java的SQL注入 Statement注入