# UPDATE CNHD BẢNG DULIEUTAIKHOAN

* Sang bản cus, có thể tài khoản công nợ mở tiểu khoản
* một số bản cũ chưa khai báo
* Tài khoản 131

```sql
--tài khoản 131
-- sửa lại groupBy cho phù hợp 
  --1.1 kiểm tra
  select ma
 ,'khachhang,sohd,serihd,mauhd,nhanvien,vung,phongban,phanxuong' as  [FieldGroupBy]
 , 'Max(case when vr.benno=1 then vr.ngayhd else ''01/01/1900'' end) as ngayhd' as [FieldAdd]
 ,'ngayhd,sohd' as [FieldOrderBy]
  from taikhoan
  where ma like '131%' and cap=0
  --1.2 insert
 insert into dulieutaikhoan (taikhoan,[FieldGroupBy],[FieldAdd],[FieldOrderBy],donvi)
 select ma
 ,'khachhang,sohd,serihd,mauhd,nhanvien,vung,phongban,phanxuong' as  [FieldGroupBy]
 , 'Max(case when vr.benno=1 then vr.ngayhd else ''01/01/1900'' end) as ngayhd' as [FieldAdd]
 ,'ngayhd,sohd' as [FieldOrderBy]
 ,1 as donvi
  from taikhoan
where ma like '131%' and cap=0
```

* Tài khoản 331

```sql
--tài khoản 331
-- sửa lại groupBy cho phù hợp  
  --1.1 kiểm tra
  select ma
 ,'khachhang,sohd,serihd,mauhd,nhanvien,vung,phongban,phanxuong' as  [FieldGroupBy]
 , 'Max(case when vr.benno=0 then vr.ngayhd else ''01/01/1900'' end) as ngayhd' as [FieldAdd]
 ,'ngayhd,sohd' as [FieldOrderBy]
  from taikhoan
  where ma like '331%' and cap=0
  --1.2 insert
 insert into dulieutaikhoan (taikhoan,[FieldGroupBy],[FieldAdd],[FieldOrderBy],donvi)
 select ma
 ,'khachhang,sohd,serihd,mauhd,nhanvien,vung,phongban,phanxuong' as  [FieldGroupBy]
 , 'Max(case when vr.benno=0 then vr.ngayhd else ''01/01/1900'' end) as ngayhd' as [FieldAdd]
 ,'ngayhd,sohd' as [FieldOrderBy]
 ,1 as donvi
  from taikhoan
where ma like '331%' and cap=0
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kythuat.dtechvn.com/danh-muc/update-cnhd-bang-dulieutaikhoan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
