> For the complete documentation index, see [llms.txt](https://kythuat.dtechvn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kythuat.dtechvn.com/dinh-muc/convert-ban-e.md).

# CONVERT BẢN E

## Nguyên tắc chung

* Sử dụng chức năng convert bảng dinhmuc1 sang&#x20;
* Cập nhật lại cột sanpham theo id mới&#x20;
* Tạo keyct của từng sản phẩm. để khi lên giao diện định mức, sản phẩm sẽ hiển thị chi tiết định mức nguyên liệu là gì

```sql
-- sau khi convert dinhmuc1 sang thì chạy các lệnh sau
-- 1. cập nhật lại cột sanpham
Update T1 set T1.sanpham = T2.vattu
from
(select * from dinhmuc where sanpham<>0 and donvi=1) T1
inner join
(select * from vattu where thanhphamcu<>0 and vattu<>0 and donvi=1) T2
on T1.sanpham = T2.thanhphamcu

-- 2. cập nhật lại keyct
select SanPham,NEWID() as keymecon into #keymecon from DinhMuc
group by SanPham
update a set a.keymecon=b.keymecon from DinhMuc a inner join #keymecon b on a.SanPham=b.SanPham

```
