笔记--终章 可以执行成功的代码

use UFTData502874_000009;
select a.id as 商品编号
,a.code as 编号
,a.NAME as 商品名称
,a.productInfo as 品牌
-- ,pa.name as 供应商
,a.specification as 规格型号
,a.lowQuantity as 最低库存量
,c.baseQuantity as 库存量单位
,c.subQuantity as 库存量辅单位
,case when a.disabled='1' then '已下架' else '正常' end as 状态
from dbo.AA_Inventory a
left join (select idinventory,baseQuantity,subQuantity from ST_CurrentStock)c on c.idinventory=a.id
where (disabled='0')-- 未停用

--left join dbo.ST_CurrentStock c on c.idinventory=a.id
--where a.lowQuantity is not null
--group by a.id,a.code,a.NAME,a.specification,a.lowQuantity

-- group by id,code,NAME,specification,lowQuantity
-- group by a.id,a.code,a.NAME,a.specification,a.lowQuantity
-- ST_CurrentStock -- 现存量表

-- select idinventory from dbo.ST_CurrentStock

-- select idinventory,pa.name
-- from dbo.Pu_PurchaseRequisition_b b
--left join (select * from dbo.Pu_PurchaseRequisition)p on p.id=b.idPurchaseRequisitionDTO
--left join (select * from dbo.AA_Partner )pa on pa.id=p.id;

-------------------------------------------------------

use UFTData502874_000009;
select * from dbo.AA_Partner where name like'%公司%';

select * from dbo.AA_Partner where name like'%凤祥%';

select * from dbo.AA_Partner where code='010003';

-- 类型为1 的是 供应商公司
select * from dbo.AA_Partner where idpartnerclass='1';

扫描二维码关注公众号,回复: 4956140 查看本文章

-- 公司编号 code 010001
-- 供应商的ID 等于 采购单的 idsuggpartner


select * from dbo.Pu_PurchaseRequisition

--insert into dbo.Pu_PurchaseRequisition
-- error
select p.code
,convert(int,p.idsuggpartner)as idsuggpartner
,p.TotalAmount
from dbo.Pu_PurchaseRequisition p


select convert(int,code)-10000 as code
,name
from dbo.AA_Partner where idpartnerclass='1'
order by code asc;
-- 对应供应商的请购单中的明细

-- 供应商的对应
select p.code,a.cd,a.name,p.TotalAmount from dbo.Pu_PurchaseRequisition p
left join (select convert(int,code)-10000 as cd
,name from dbo.AA_Partner )a on p.idsuggpartner=a.cd
-------------------------------------------------------------------------------------------------
select distinct(isPurchase) from dbo.AA_Inventory

select distinct(disabled) from dbo.AA_Inventory
-- 0有用 1 下架停用


-- 编号 boss后台查询商品要加2018 加上编号


select COUNT(*) from dbo.AA_Inventory


----------------------------------------------------
insert into dbo.Pu_PurchaseRequisition_b
(--code, --编号
quantity -- 袋数量
,unitExchangeRate -- 转换率
,quantity2 -- 箱数量
,compositionQuantity -- 箱数+单位
,discountRate -- 折扣率1.00000000*
,discountPrice -- 折扣价格
,taxRate -- 税率 select
,taxPrice --select
,discountAmount --se
,tax --se
,taxAmount -- se
,isPraRequire -- 0
,baseQuantity --基础数量
,praRequireTimes -- 0
,updatedBy -- 更新时间 getdate()
,taxFlag --0
,islaborcost--0
,idinventory -- 编号
,idsuggpartner --建议供应商
,idbaseunit -- 规格
,idsubunit -- 辅规格
,idunit -- 规格
,idunit2 --辅规格
,idPurchaseRequisitionDTO -- 单据编号 对应前面的Q*
,requireDate -- 日期getdate()
,updated -- 当前日期 current
,detailVoucherState --执行状态 没有为空
,IsModifiedPrice -- 没有修改0 否则为1
)

select
quantity2*p.unitExchangeRate as quality, --quality
p.unitExchangeRate -- unitExchangeRate
,(a.lowQuantity-c.baseQuantity)as quantity2 --quantity2
,cast(quantity2 as varchar(20))+'箱' as compositionQuantity--compositionQuantity
,p.discountRate --discountRate
,p.discountPrice--discountPrice
,p.taxRate--taxRate
,p.taxPrice --taxPrice
,p.discountAmount--discountAmount
,p.tax--tax
,p.taxAmount--taxAmount
,0 as isPraRequire--isPraRequire
,c.baseQuantity--baseQuantity
,0 as praRequireTimes--praRequireTimes
,15251913663 as updatedBy--updatedBy
,0 as taxFlag--taxFlag
,0 as islaborcost--islaborcost
,c.idinventory--idinventory
,null as idsuggpartner--idsuggpartner
,p.idbaseunit--idbaseunit
,p.idsubunit--idsubunit
,p.idunit--idunit
,p.idunit2--idunit2
,5 as idPurchaseRequisitionDTO--idPurchaseRequisitionDTO
,GETDATE() as requireDate --requireDate
,getdate() as updated --updated
,null as detailVoucherState--detailVoucherState
,0 as IsModifiedPrice--IsModifiedPrice未改0
from dbo.AA_Inventory a
left join dbo.ST_CurrentStock c on c.idinventory=a.id
--left join dbo.PU_PurchaseArrival_b p on p.idinventory=a.id
left join dbo.PU_PurchaseArrival_b p on p.idinventory=c.idinventory
where (disabled='0')
and c.baseQuantity is null
or
a.lowQuantity>c.baseQuantity


--UPDATE dbo.Pu_PurchaseRequisition_b
--SET code = CASE WHEN code IS NULL THEN 0 ELSE code + 1 END;

--
--update dbo.Pu_PurchaseRequisition_b
--set code = cast(cast(code as int) + 1 as varchar(12))

update dbo.Pu_PurchaseRequisition_b set dbo.Pu_PurchaseRequisition_b.code = b.r
from dbo.Pu_PurchaseRequisition_b
left join (select a.pk, case a.r % 500
when 0 then 500 else a.r % 500 end as r
from (
select id as pk,row_number() over(order by 主键) as r
from dbo.Pu_PurchaseRequisition_b ) a) b on dbo.Pu_PurchaseRequisition_b.id = b.pk
-- unoin all
-----------------------------------------------------------------------------
select distinct a.id as 商品编号
,a.code as 编号
,a.NAME as 商品名称
,a.productInfo as 品牌
-- ,pa.name as 供应商
,a.specification as 规格型号
,a.lowQuantity as 最低库存量
,c.baseQuantity as 库存量单位
,c.subQuantity as 库存量辅单位
,case when a.disabled='1' then '已下架' else '正常' end as 状态
from dbo.AA_Inventory a
left join (select idinventory,baseQuantity,subQuantity from ST_CurrentStock)c on c.idinventory=a.id
where (disabled='0')
and c.baseQuantity is null
or
a.lowQuantity>c.baseQuantity

猜你喜欢

转载自www.cnblogs.com/danJuly/p/10283412.html