123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751 |
- <?xml version="1.0" encoding="utf-8" ?>
- <Forms>
- <Form Name="FrmYearSalesStatistics">
- <Client>
- <Events>
- <Load>
- <![CDATA[
- @Title="年度销售统计";
- GetSchema();
- Search("SearchCompany");
- ChangeMode("Search");
- ]]>
- </Load>
- <EndLoad>
- <![CDATA[
- for(@i=0;@i < CLB_Company.GetItemsCount();@i++)
- {
- CLB_Company.SetItemChecked(@i,true);
- }
- ]]>
- </EndLoad>
- <Closing>
- ;
- </Closing>
- <Closed>
- ;
- </Closed>
- </Events>
- <Mode>
- <Search>
- <Lable name="Search"/>
- </Search>
- </Mode>
- <Controls>
- <IKDateTimePicker name = "dtDate"></IKDateTimePicker>
- <IKCheckedListBox name="CLB_Company" DataSource="Company" DisplayMember="ShortName_Company" ValueMember="ID_Company">
- <Events>
- <ItemCheck>
- if(CLB_Company.SelectedIndex == 0)
- CLB_Location.SelectAllItems();
- </ItemCheck>
- </Events>
- </IKCheckedListBox>
- <IKButton name="btnView">
- <Events>
- <Click>
- <![CDATA[
- @sqlCompany="";
- @empty=true;
- @first=true;
- for(@i=1;@i < CLB_Company.GetItemsCount();@i++){
- if(CLB_Company.GetItemChecked(@i)){
- @empty=false;
- if(@first==true){
- @sqlCompany=@sqlCompany+CLB_Company.GetSelectedName(@i);
- @first=false;
- }else{
- @sqlCompany=@sqlCompany+","+CLB_Company.GetSelectedName(@i);
- }
- }
- }
- if(@empty==true)
- {
- MessageBox("请选择公司!",@Title);
- return;
- }
-
- @DateTime = DBNull();
- if (dtDate.Checked)
- {
- @DateTime = dtDate.Value;
- }
- else
- {
- MessageBox("请选择当前日期!",@Title);
- return;
- }
- Search("SearchYearSalesStatistics",@sqlCompany,@DateTime);
- if(RowCount("#FrmYearSalesStatistics") ==0)
- {
- MessageBox("没有查找到与此相匹配的纪录,未产生报表!",@Title);
- }
- else
- {
- PrintReport("GetFrmYearSalesStatistics","Get","FrmYearSalesStatistics");
- }
- ]]>
- </Click>
- </Events>
- </IKButton>
- <IKButton name="btnExcel">
- <Events>
- <Click>
- <![CDATA[
- @sqlCompany="";
- @empty=true;
- @first=true;
- for(@i=1;@i < CLB_Company.GetItemsCount();@i++){
- if(CLB_Company.GetItemChecked(@i)){
- @empty=false;
- if(@first==true){
- @sqlCompany=@sqlCompany+CLB_Company.GetSelectedName(@i);
- @first=false;
- }else{
- @sqlCompany=@sqlCompany+","+CLB_Company.GetSelectedName(@i);
- }
- }
- }
- if(@empty==true)
- {
- MessageBox("请选择公司!",@Title);
- return;
- }
-
- @DateTime = DBNull();
- if (dtDate.Checked)
- {
- @DateTime = dtDate.Value;
- }
- else
- {
- MessageBox("请选择当前日期!",@Title);
- return;
- }
- Search("SearchYearSalesStatistics",@sqlCompany,@DateTime);
- if(RowCount("#FrmYearSalesStatistics") ==0)
- {
- MessageBox("没有查找到与此相匹配的纪录,未产生报表!",@Title);
- }
- else
- {
- ExportReport("Excel","GetFrmYearSalesStatistics","Get","FrmYearSalesStatistics");
- }
- ]]>
- </Click>
- </Events>
- </IKButton>
- <IKButton name="btnWord">
- <Events>
- <Click>
- <![CDATA[
- @sqlCompany="";
- @empty=true;
- @first=true;
- for(@i=1;@i < CLB_Company.GetItemsCount();@i++){
- if(CLB_Company.GetItemChecked(@i)){
- @empty=false;
- if(@first==true){
- @sqlCompany=@sqlCompany+CLB_Company.GetSelectedName(@i);
- @first=false;
- }else{
- @sqlCompany=@sqlCompany+","+CLB_Company.GetSelectedName(@i);
- }
- }
- }
- if(@empty==true)
- {
- MessageBox("请选择公司!",@Title);
- return;
- }
-
- @DateTime = DBNull();
- if (dtDate.Checked)
- {
- @DateTime = dtDate.Value;
- }
- else
- {
- MessageBox("请选择当前日期!",@Title);
- return;
- }
- Search("SearchYearSalesStatistics",@sqlCompany,@DateTime);
- if(RowCount("#FrmYearSalesStatistics") ==0)
- {
- MessageBox("没有查找到与此相匹配的纪录,未产生报表!",@Title);
- }
- else
- {
- ExportReport("Word","GetFrmYearSalesStatistics","Get","FrmYearSalesStatistics");
- }
- ]]>
- </Click>
- </Events>
- </IKButton>
- <IKButton name="btnPrint">
- <Events>
- <Click>
- <![CDATA[
- @sqlCompany="";
- @empty=true;
- @first=true;
- for(@i=1;@i < CLB_Company.GetItemsCount();@i++){
- if(CLB_Company.GetItemChecked(@i)){
- @empty=false;
- if(@first==true){
- @sqlCompany=@sqlCompany+CLB_Company.GetSelectedName(@i);
- @first=false;
- }else{
- @sqlCompany=@sqlCompany+","+CLB_Company.GetSelectedName(@i);
- }
- }
- }
- if(@empty==true)
- {
- MessageBox("请选择公司!",@Title);
- return;
- }
-
- @DateTime = DBNull();
- if (dtDate.Checked)
- {
- @DateTime = dtDate.Value;
- }
- else
- {
- MessageBox("请选择当前日期!",@Title);
- return;
- }
- Search("SearchYearSalesStatistics",@sqlCompany,@DateTime);
- if(RowCount("#FrmYearSalesStatistics") ==0)
- {
- MessageBox("没有查找到与此相匹配的纪录,未产生报表!",@Title);
- }
- else
- {
- ExportReport("PrintToPrinter","GetFrmYearSalesStatistics","Get","FrmYearSalesStatistics");
- }
- ]]>
- </Click>
-
- </Events>
- </IKButton>
- </Controls>
- </Client>
- <Server>
- <Table>
- <Table name="Get" Type="Parent">
- <GetSchema CmdType="Text" CmdText="SELECT TOP 0 convert(datetime,0) as DateTime"/>
- </Table>
- <Table name="FrmYearSalesStatistics" Type="Other">
- <GetSchema CmdType="Text" CmdText="Select Top 0 Convert(Nvarchar(64),'') As No_Product,
- Convert(Nvarchar(64),'') As Name_Product,
- Convert(Decimal(14,2),0) As ThreeY_SaleAmount,
- Convert(Decimal(14,2),0) As TwoY_SaleAmount,
- Convert(Decimal(14,2),0) As OneY_SaleAmount,
- Convert(Decimal(14,2),0) As ThreeM_SaleAmount,
- Convert(Decimal(14,2),0) As StockQty_ProductStocks,
- Convert(Decimal(14,2),0) As NotArrive_Amount,
- Convert(Decimal(14,2),0) As Quantity_OnShip,
- Convert(Nvarchar(64),0) As No_PurchaseOrderBill,
- Convert(Nvarchar(64),'') As RefNo_PurchaseOrderBill,
- Convert(Nvarchar(64),0) As No_PurchaseOrderBillProduct,
- Convert(Decimal(14,2),0) As PNotArrive_Amount,
- Convert(Decimal(14,2),0) As PQuantity_OnShip"/>
- </Table>
- </Table>
- <Search>
- <SearchCompany CmdType="Text" CmdText="Use [SunRoxmManager] Select ShortName_Company,ID_Company from Company where Private_Company = 1
- ">
- <Tables>
- <Table name="Company"/>
- </Tables>
- </SearchCompany>
- <SearchYearSalesStatistics CmdType="Text" CmdText="Select [DateTime] = @DateTime
-
- Declare @DataBase_Company Nvarchar(64)
-
- CREATE TABLE [SunRoxmManager].[dbo].[Temp] ( company [Nvarchar] (64))
- declare @Company nvarchar(64)
- declare @tmpDay varchar(10)
- set @tmpDay=''
- declare @i int
- set @i=0
- while @i < len(@sqlCompany)
- begin
- set @i=@i+1
- if SUBSTRING(@sqlCompany,@i,1)=','
- begin
- insert into [SunRoxmManager].[dbo].[Temp] values(left(@sqlCompany,@i-1))
- set @sqlCompany=SUBSTRING(@sqlCompany,@i+1,len(@sqlCompany))
- set @i=0
- end
- end
- insert into [SunRoxmManager].[dbo].[Temp] values(@sqlCompany)
-
- declare @sql nvarchar(4000)
- set @sql = ''
- Set @sql = @sql + ' Select No_Product,Name_Product,P.ID_Product,IsNull(ThreeY_SaleAmount,0) As ThreeY_SaleAmount,IsNull(TwoY_SaleAmount,0) As TwoY_SaleAmount, IsNull(OneY_SaleAmount,0) As OneY_SaleAmount, IsNull(ThreeM_SaleAmount,0) As ThreeM_SaleAmount,IsNull(ps.StockQty_ProductStocks,0) As StockQty_ProductStocks,'
- +' IsNull(NotArrive_Amount,0) As NotArrive_Amount,IsNull(Quantity_OnShip,0) As Quantity_OnShip,No_PurchaseOrderBill,RefNo_PurchaseOrderBill,Comment_PurchaseOrderBillProduct,IsNull(PNotArrive_Amount,0) As PNotArrive_Amount,IsNull(PQuantity_OnShip,0) As PQuantity_OnShip From ('
-
- Declare @CountP int
- Set @CountP = 0
- Declare @sqlP nvarchar(4000)
- set @sqlP = ''
- Set @sqlP = @sqlP +' Select AP.ID_Product From ('
- Declare CurP Cursor for Select DataBase_Company From [SunRoxmManager].dbo.Company Where ShortName_Company In (select * from [SunRoxmManager].[dbo].[Temp])
- Open CurP
- Fetch Next From CurP Into @DataBase_Company
- While @@Fetch_Status = 0
- Begin
- If(@CountP = 0)
- Begin
- Set @sqlP = @sqlP + ' Select [' + @DataBase_Company + '].DBO.Product.ID_Product From [' + @DataBase_Company + '].DBO.Product'
- End
- If(@CountP > 0)
- Begin
- Set @sqlP = @sqlP + ' Union All Select [' + @DataBase_Company + '].DBO.Product.ID_Product From [' + @DataBase_Company + '].DBO.Product'
- End
- Set @CountP = @CountP + 1
- Fetch Next From CurP Into @DataBase_Company
- End
- Close CurP
- Deallocate CurP
- Set @sqlP = @sqlP+' ) AP Group By AP.ID_Product'
- Set @sqlP = @sqlP +' ) P '
-
-
- Declare @Count3 int
- Set @Count3 = 0
- declare @sql3 nvarchar(4000)
- set @sql3 = ''
- declare @sql7 nvarchar(4000)
- set @sql7 = ''
- Set @sql3 = @sql3 + ' Left Join( Select ID_Product,(Sum(Quantity_SaleAmount)-Sum(IsNull(Quantity_SaleBillProduct,0))+Sum(IsNull(Quantity_SaleRtnBillProduct,0))) As ThreeY_SaleAmount From ('
- Declare Cur3 Cursor for Select DataBase_Company From [SunRoxmManager].dbo.Company Where ShortName_Company In (select * from [SunRoxmManager].[dbo].[Temp])
- Open Cur3
- Fetch Next From Cur3 Into @DataBase_Company
- While @@Fetch_Status = 0
- Begin
-
- If(@Count3 = 0)
- Begin
- Set @sql3 = @sql3 +' Select D3'+convert(nvarchar,@Count3)+'.ID_Product,D3'+convert(nvarchar,@Count3)+'.Quantity_SaleAmount,B3'+convert(nvarchar,@Count3)+'.Quantity_SaleBillProduct,C3'+convert(nvarchar,@Count3)+'.Quantity_SaleRtnBillProduct From ('
- +' Select AA3'+convert(nvarchar,@Count3)+'.ID_Product, (IsNull(AA3'+convert(nvarchar,@Count3)+'.Quantity_SaleBillProduct,0)- IsNull(CC3'+convert(nvarchar,@Count3)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA3'+convert(nvarchar,@Count3)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB3'+convert(nvarchar,@Count3)+' On BB3'+convert(nvarchar,@Count3)+'.ID_SaleBill = AA3'+convert(nvarchar,@Count3)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC3'+convert(nvarchar,@Count3)+' On CC3'+convert(nvarchar,@Count3)+'.No_FromBill = BB3'+convert(nvarchar,@Count3)+'.No_SaleBill And CC3'+convert(nvarchar,@Count3)+'.No_FromBillProduct = AA3'+convert(nvarchar,@Count3)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD3'+convert(nvarchar,@Count3)+' On DD3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill = CC3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill'
- +' And DD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill < DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD3'+convert(nvarchar,@Count3)+'.ID_Assessor Is Not Null'
- +' Where BB3'+convert(nvarchar,@Count3)+'.ID_Assessor Is Not Null '
- +' And BB3'+convert(nvarchar,@Count3)+'.Date_SaleBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB3'+convert(nvarchar,@Count3)+'.Date_SaleBill < DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BB3'+convert(nvarchar,@Count3)+'.IsImport_SaleBill = 0) D3'+convert(nvarchar,@Count3)
-
- +' Left Join (Select AAAA3'+convert(nvarchar,@Count3)+'.ID_Product,AAAA3'+convert(nvarchar,@Count3)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA3'+convert(nvarchar,@Count3)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB3'+convert(nvarchar,@Count3)+' On BBBB3'+convert(nvarchar,@Count3)+'.ID_SaleBill = AAAA3'+convert(nvarchar,@Count3)+'.ID_SaleBill'
- +' Where BBBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill <DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB3'+convert(nvarchar,@Count3)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B3'+convert(nvarchar,@Count3)+' On B3'+convert(nvarchar,@Count3)+'.ID_Product = D3'+convert(nvarchar,@Count3)+'.ID_Product '
-
- +' Left Join( Select AAA3'+convert(nvarchar,@Count3)+'.ID_Product, CCC3'+convert(nvarchar,@Count3)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA3'+convert(nvarchar,@Count3)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB3'+convert(nvarchar,@Count3)+' On BBB3'+convert(nvarchar,@Count3)+'.ID_SaleBill = AAA3'+convert(nvarchar,@Count3)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC3'+convert(nvarchar,@Count3)+' On CCC3'+convert(nvarchar,@Count3)+'.No_FromBill = BBB3'+convert(nvarchar,@Count3)+'.No_SaleBill And CCC3'+convert(nvarchar,@Count3)+'.No_FromBillProduct = AAA3'+convert(nvarchar,@Count3)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD3'+convert(nvarchar,@Count3)+' On DDD3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill = CCC3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill'
- +' And DDD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill <DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' Where BBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill <DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BBB3'+convert(nvarchar,@Count3)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C3'+convert(nvarchar,@Count3)+' On C3'+convert(nvarchar,@Count3)+'.ID_Product = D3'+convert(nvarchar,@Count3)+'.ID_Product '
- End
- If(@Count3 > 0)
- Begin
- Set @sql7 = @sql7 + ' Union All Select D3'+convert(nvarchar,@Count3)+'.ID_Product,D3'+convert(nvarchar,@Count3)+'.Quantity_SaleAmount,B3'+convert(nvarchar,@Count3)+'.Quantity_SaleBillProduct,C3'+convert(nvarchar,@Count3)+'.Quantity_SaleRtnBillProduct From ('
- +'Select AA3'+convert(nvarchar,@Count3)+'.ID_Product, (IsNull(AA3'+convert(nvarchar,@Count3)+'.Quantity_SaleBillProduct,0)- IsNull(CC3'+convert(nvarchar,@Count3)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA3'+convert(nvarchar,@Count3)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB3'+convert(nvarchar,@Count3)+' On BB3'+convert(nvarchar,@Count3)+'.ID_SaleBill = AA3'+convert(nvarchar,@Count3)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC3'+convert(nvarchar,@Count3)+' On CC3'+convert(nvarchar,@Count3)+'.No_FromBill = BB3'+convert(nvarchar,@Count3)+'.No_SaleBill And CC3'+convert(nvarchar,@Count3)+'.No_FromBillProduct = AA3'+convert(nvarchar,@Count3)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD3'+convert(nvarchar,@Count3)+' On DD3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill = CC3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill'
- +' And DD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill < DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD3'+convert(nvarchar,@Count3)+'.ID_Assessor Is Not Null'
- +' Where BB3'+convert(nvarchar,@Count3)+'.ID_Assessor Is Not Null '
- +' And BB3'+convert(nvarchar,@Count3)+'.Date_SaleBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB3'+convert(nvarchar,@Count3)+'.Date_SaleBill < DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BB3'+convert(nvarchar,@Count3)+'.IsImport_SaleBill = 0) D3'+convert(nvarchar,@Count3)
-
- +' Left Join (Select AAAA3'+convert(nvarchar,@Count3)+'.ID_Product,AAAA3'+convert(nvarchar,@Count3)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA3'+convert(nvarchar,@Count3)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB3'+convert(nvarchar,@Count3)+' On BBBB3'+convert(nvarchar,@Count3)+'.ID_SaleBill = AAAA3'+convert(nvarchar,@Count3)+'.ID_SaleBill'
- +' Where BBBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill <DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB3'+convert(nvarchar,@Count3)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B3'+convert(nvarchar,@Count3)+' On B3'+convert(nvarchar,@Count3)+'.ID_Product = D3'+convert(nvarchar,@Count3)+'.ID_Product '
-
- +' Left Join( Select AAA3'+convert(nvarchar,@Count3)+'.ID_Product, CCC3'+convert(nvarchar,@Count3)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA3'+convert(nvarchar,@Count3)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB3'+convert(nvarchar,@Count3)+' On BBB3'+convert(nvarchar,@Count3)+'.ID_SaleBill = AAA3'+convert(nvarchar,@Count3)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC3'+convert(nvarchar,@Count3)+' On CCC3'+convert(nvarchar,@Count3)+'.No_FromBill = BBB3'+convert(nvarchar,@Count3)+'.No_SaleBill And CCC3'+convert(nvarchar,@Count3)+'.No_FromBillProduct = AAA3'+convert(nvarchar,@Count3)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD3'+convert(nvarchar,@Count3)+' On DDD3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill = CCC3'+convert(nvarchar,@Count3)+'.ID_SaleRtnBill'
- +' And DDD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD3'+convert(nvarchar,@Count3)+'.Date_SaleRtnBill <DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' Where BBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill > DateAdd(yy,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB3'+convert(nvarchar,@Count3)+'.Date_SaleBill <DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BBB3'+convert(nvarchar,@Count3)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C3'+convert(nvarchar,@Count3)+' On C3'+convert(nvarchar,@Count3)+'.ID_Product = D3'+convert(nvarchar,@Count3)+'.ID_Product '
- End
-
- Set @Count3 = @Count3 + 1
- Fetch Next From Cur3 Into @DataBase_Company
- End
- Close Cur3
- Deallocate Cur3
- Set @sql7 = @sql7+' ) A3 Group By A3.ID_Product'
- Set @sql7 = @sql7 +' ) ThreeY On ThreeY.ID_Product = P.ID_Product'
- Declare @Count2 int
- Set @Count2 = 0
- declare @sql2 nvarchar(4000)
- set @sql2 = ''
- declare @sql8 nvarchar(4000)
- set @sql8 = ''
- Set @sql2 = @sql2 + ' Left Join( Select ID_Product,(Sum(Quantity_SaleAmount)-Sum(IsNull(Quantity_SaleBillProduct,0))+Sum(IsNull(Quantity_SaleRtnBillProduct,0))) As TwoY_SaleAmount From ('
- Declare Cur2 Cursor for Select DataBase_Company From [SunRoxmManager].dbo.Company Where ShortName_Company In (select * from [SunRoxmManager].[dbo].[Temp])
- Open Cur2
- Fetch Next From Cur2 Into @DataBase_Company
- While @@Fetch_Status = 0
- Begin
-
- If(@Count2 = 0)
- Begin
- Set @sql2 = @sql2 +' Select D2'+convert(nvarchar,@Count2)+'.ID_Product,D2'+convert(nvarchar,@Count2)+'.Quantity_SaleAmount,B2'+convert(nvarchar,@Count2)+'.Quantity_SaleBillProduct,C2'+convert(nvarchar,@Count2)+'.Quantity_SaleRtnBillProduct From ('
- +' Select AA2'+convert(nvarchar,@Count2)+'.ID_Product, (IsNull(AA2'+convert(nvarchar,@Count2)+'.Quantity_SaleBillProduct,0)- IsNull(CC2'+convert(nvarchar,@Count2)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA2'+convert(nvarchar,@Count2)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB2'+convert(nvarchar,@Count2)+' On BB2'+convert(nvarchar,@Count2)+'.ID_SaleBill = AA2'+convert(nvarchar,@Count2)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC2'+convert(nvarchar,@Count2)+' On CC2'+convert(nvarchar,@Count2)+'.No_FromBill = BB2'+convert(nvarchar,@Count2)+'.No_SaleBill And CC2'+convert(nvarchar,@Count2)+'.No_FromBillProduct = AA2'+convert(nvarchar,@Count2)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD2'+convert(nvarchar,@Count2)+' On DD2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill = CC2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill'
- +' And DD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill < DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD2'+convert(nvarchar,@Count2)+'.ID_Assessor Is Not Null'
- +' Where BB2'+convert(nvarchar,@Count2)+'.ID_Assessor Is Not Null '
- +' And BB2'+convert(nvarchar,@Count2)+'.Date_SaleBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB2'+convert(nvarchar,@Count2)+'.Date_SaleBill < DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BB2'+convert(nvarchar,@Count2)+'.IsImport_SaleBill = 0) D2'+convert(nvarchar,@Count2)
-
- +' Left Join (Select AAAA2'+convert(nvarchar,@Count2)+'.ID_Product,AAAA2'+convert(nvarchar,@Count2)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA2'+convert(nvarchar,@Count2)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB2'+convert(nvarchar,@Count2)+' On BBBB2'+convert(nvarchar,@Count2)+'.ID_SaleBill = AAAA2'+convert(nvarchar,@Count2)+'.ID_SaleBill'
- +' Where BBBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill <DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB2'+convert(nvarchar,@Count2)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B2'+convert(nvarchar,@Count2)+' On B2'+convert(nvarchar,@Count2)+'.ID_Product = D2'+convert(nvarchar,@Count2)+'.ID_Product '
-
- +' Left Join( Select AAA2'+convert(nvarchar,@Count2)+'.ID_Product, CCC2'+convert(nvarchar,@Count2)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA2'+convert(nvarchar,@Count2)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB2'+convert(nvarchar,@Count2)+' On BBB2'+convert(nvarchar,@Count2)+'.ID_SaleBill = AAA2'+convert(nvarchar,@Count2)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC2'+convert(nvarchar,@Count2)+' On CCC2'+convert(nvarchar,@Count2)+'.No_FromBill = BBB2'+convert(nvarchar,@Count2)+'.No_SaleBill And CCC2'+convert(nvarchar,@Count2)+'.No_FromBillProduct = AAA2'+convert(nvarchar,@Count2)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD2'+convert(nvarchar,@Count2)+' On DDD2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill = CCC2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill'
- +' And DDD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill <DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' Where BBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill <DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
-
- +' And BBB2'+convert(nvarchar,@Count2)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C2'+convert(nvarchar,@Count2)+' On C2'+convert(nvarchar,@Count2)+'.ID_Product = D2'+convert(nvarchar,@Count2)+'.ID_Product '
- End
- If(@Count2 > 0)
- Begin
- Set @sql8 = @sql8 + ' Union All Select D2'+convert(nvarchar,@Count2)+'.ID_Product,D2'+convert(nvarchar,@Count2)+'.Quantity_SaleAmount,B2'+convert(nvarchar,@Count2)+'.Quantity_SaleBillProduct,C2'+convert(nvarchar,@Count2)+'.Quantity_SaleRtnBillProduct From ('
- +'Select AA2'+convert(nvarchar,@Count2)+'.ID_Product, (IsNull(AA2'+convert(nvarchar,@Count2)+'.Quantity_SaleBillProduct,0)- IsNull(CC2'+convert(nvarchar,@Count2)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA2'+convert(nvarchar,@Count2)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB2'+convert(nvarchar,@Count2)+' On BB2'+convert(nvarchar,@Count2)+'.ID_SaleBill = AA2'+convert(nvarchar,@Count2)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC2'+convert(nvarchar,@Count2)+' On CC2'+convert(nvarchar,@Count2)+'.No_FromBill = BB2'+convert(nvarchar,@Count2)+'.No_SaleBill And CC2'+convert(nvarchar,@Count2)+'.No_FromBillProduct = AA2'+convert(nvarchar,@Count2)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD2'+convert(nvarchar,@Count2)+' On DD2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill = CC2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill'
- +' And DD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill < DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD2'+convert(nvarchar,@Count2)+'.ID_Assessor Is Not Null'
- +' Where BB2'+convert(nvarchar,@Count2)+'.ID_Assessor Is Not Null '
- +' And BB2'+convert(nvarchar,@Count2)+'.Date_SaleBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB2'+convert(nvarchar,@Count2)+'.Date_SaleBill < DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BB2'+convert(nvarchar,@Count2)+'.IsImport_SaleBill = 0) D2'+convert(nvarchar,@Count2)
-
- +' Left Join (Select AAAA2'+convert(nvarchar,@Count2)+'.ID_Product,AAAA2'+convert(nvarchar,@Count2)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA2'+convert(nvarchar,@Count2)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB2'+convert(nvarchar,@Count2)+' On BBBB2'+convert(nvarchar,@Count2)+'.ID_SaleBill = AAAA2'+convert(nvarchar,@Count2)+'.ID_SaleBill'
- +' Where BBBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill <DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB2'+convert(nvarchar,@Count2)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B2'+convert(nvarchar,@Count2)+' On B2'+convert(nvarchar,@Count2)+'.ID_Product = D2'+convert(nvarchar,@Count2)+'.ID_Product '
-
- +' Left Join( Select AAA2'+convert(nvarchar,@Count2)+'.ID_Product, CCC2'+convert(nvarchar,@Count2)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA2'+convert(nvarchar,@Count2)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB2'+convert(nvarchar,@Count2)+' On BBB2'+convert(nvarchar,@Count2)+'.ID_SaleBill = AAA2'+convert(nvarchar,@Count2)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC2'+convert(nvarchar,@Count2)+' On CCC2'+convert(nvarchar,@Count2)+'.No_FromBill = BBB2'+convert(nvarchar,@Count2)+'.No_SaleBill And CCC2'+convert(nvarchar,@Count2)+'.No_FromBillProduct = AAA2'+convert(nvarchar,@Count2)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD2'+convert(nvarchar,@Count2)+' On DDD2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill = CCC2'+convert(nvarchar,@Count2)+'.ID_SaleRtnBill'
- +' And DDD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD2'+convert(nvarchar,@Count2)+'.Date_SaleRtnBill <DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' Where BBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill > DateAdd(yy,-2,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB2'+convert(nvarchar,@Count2)+'.Date_SaleBill <DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
-
- +' And BBB2'+convert(nvarchar,@Count2)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C2'+convert(nvarchar,@Count2)+' On C2'+convert(nvarchar,@Count2)+'.ID_Product = D2'+convert(nvarchar,@Count2)+'.ID_Product '
- End
-
- Set @Count2 = @Count2 + 1
- Fetch Next From Cur2 Into @DataBase_Company
- End
- Close Cur2
- Deallocate Cur2
- Set @sql8 = @sql8 +' ) A2 Group By A2.ID_Product'
- Set @sql8 = @sql8 +' ) TwoY On TwoY.ID_Product = P.ID_Product'
- Declare @Count1 int
- Set @Count1 = 0
- declare @sql1 nvarchar(4000)
- set @sql1 = ''
- declare @sql9 nvarchar(4000)
- set @sql9 = ''
- Set @sql1 = @sql1 + ' Left Join( Select ID_Product,(Sum(Quantity_SaleAmount)-Sum(IsNull(Quantity_SaleBillProduct,0))+Sum(IsNull(Quantity_SaleRtnBillProduct,0))) As OneY_SaleAmount From ('
- Declare Cur1 Cursor for Select DataBase_Company From [SunRoxmManager].dbo.Company Where ShortName_Company In (select * from [SunRoxmManager].[dbo].[Temp])
- Open Cur1
- Fetch Next From Cur1 Into @DataBase_Company
- While @@Fetch_Status = 0
- Begin
-
- If(@Count1 = 0)
- Begin
- Set @sql1 = @sql1 +' Select D1'+convert(nvarchar,@Count1)+'.ID_Product,D1'+convert(nvarchar,@Count1)+'.Quantity_SaleAmount,B1'+convert(nvarchar,@Count1)+'.Quantity_SaleBillProduct,C1'+convert(nvarchar,@Count1)+'.Quantity_SaleRtnBillProduct From ('
- +' Select AA1'+convert(nvarchar,@Count1)+'.ID_Product, (IsNull(AA1'+convert(nvarchar,@Count1)+'.Quantity_SaleBillProduct,0)- IsNull(CC1'+convert(nvarchar,@Count1)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA1'+convert(nvarchar,@Count1)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB1'+convert(nvarchar,@Count1)+' On BB1'+convert(nvarchar,@Count1)+'.ID_SaleBill = AA1'+convert(nvarchar,@Count1)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC1'+convert(nvarchar,@Count1)+' On CC1'+convert(nvarchar,@Count1)+'.No_FromBill = BB1'+convert(nvarchar,@Count1)+'.No_SaleBill And CC1'+convert(nvarchar,@Count1)+'.No_FromBillProduct = AA1'+convert(nvarchar,@Count1)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD1'+convert(nvarchar,@Count1)+' On DD1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill = CC1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill'
- +' And DD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And DD1'+convert(nvarchar,@Count1)+'.ID_Assessor Is Not Null'
- +' Where BB1'+convert(nvarchar,@Count1)+'.ID_Assessor Is Not Null '
- +' And BB1'+convert(nvarchar,@Count1)+'.Date_SaleBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB1'+convert(nvarchar,@Count1)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BB1'+convert(nvarchar,@Count1)+'.IsImport_SaleBill = 0) D1'+convert(nvarchar,@Count1)
-
- +' Left Join (Select AAAA1'+convert(nvarchar,@Count1)+'.ID_Product,AAAA1'+convert(nvarchar,@Count1)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA1'+convert(nvarchar,@Count1)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB1'+convert(nvarchar,@Count1)+' On BBBB1'+convert(nvarchar,@Count1)+'.ID_SaleBill = AAAA1'+convert(nvarchar,@Count1)+'.ID_SaleBill'
- +' Where BBBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And BBBB1'+convert(nvarchar,@Count1)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B1'+convert(nvarchar,@Count1)+' On B1'+convert(nvarchar,@Count1)+'.ID_Product = D1'+convert(nvarchar,@Count1)+'.ID_Product '
-
- +' Left Join( Select AAA1'+convert(nvarchar,@Count1)+'.ID_Product, CCC1'+convert(nvarchar,@Count1)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA1'+convert(nvarchar,@Count1)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB1'+convert(nvarchar,@Count1)+' On BBB1'+convert(nvarchar,@Count1)+'.ID_SaleBill = AAA1'+convert(nvarchar,@Count1)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC1'+convert(nvarchar,@Count1)+' On CCC1'+convert(nvarchar,@Count1)+'.No_FromBill = BBB1'+convert(nvarchar,@Count1)+'.No_SaleBill And CCC1'+convert(nvarchar,@Count1)+'.No_FromBillProduct = AAA1'+convert(nvarchar,@Count1)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD1'+convert(nvarchar,@Count1)+' On DDD1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill = CCC1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill'
- +' And DDD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' Where BBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BBB1'+convert(nvarchar,@Count1)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C1'+convert(nvarchar,@Count1)+' On C1'+convert(nvarchar,@Count1)+'.ID_Product = D1'+convert(nvarchar,@Count1)+'.ID_Product '
- End
- If(@Count1 > 0)
- Begin
- Set @sql9 = @sql9 + 'Union All Select D1'+convert(nvarchar,@Count1)+'.ID_Product,D1'+convert(nvarchar,@Count1)+'.Quantity_SaleAmount,B1'+convert(nvarchar,@Count1)+'.Quantity_SaleBillProduct,C1'+convert(nvarchar,@Count1)+'.Quantity_SaleRtnBillProduct From ('
- +'Select AA1'+convert(nvarchar,@Count1)+'.ID_Product, (IsNull(AA1'+convert(nvarchar,@Count1)+'.Quantity_SaleBillProduct,0)- IsNull(CC1'+convert(nvarchar,@Count1)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA1'+convert(nvarchar,@Count1)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB1'+convert(nvarchar,@Count1)+' On BB1'+convert(nvarchar,@Count1)+'.ID_SaleBill = AA1'+convert(nvarchar,@Count1)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC1'+convert(nvarchar,@Count1)+' On CC1'+convert(nvarchar,@Count1)+'.No_FromBill = BB1'+convert(nvarchar,@Count1)+'.No_SaleBill And CC1'+convert(nvarchar,@Count1)+'.No_FromBillProduct = AA1'+convert(nvarchar,@Count1)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD1'+convert(nvarchar,@Count1)+' On DD1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill = CC1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill'
- +' And DD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And DD1'+convert(nvarchar,@Count1)+'.ID_Assessor Is Not Null'
- +' Where BB1'+convert(nvarchar,@Count1)+'.ID_Assessor Is Not Null '
- +' And BB1'+convert(nvarchar,@Count1)+'.Date_SaleBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB1'+convert(nvarchar,@Count1)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BB1'+convert(nvarchar,@Count1)+'.IsImport_SaleBill = 0) D1'+convert(nvarchar,@Count1)
-
- +' Left Join (Select AAAA1'+convert(nvarchar,@Count1)+'.ID_Product,AAAA1'+convert(nvarchar,@Count1)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA1'+convert(nvarchar,@Count1)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB1'+convert(nvarchar,@Count1)+' On BBBB1'+convert(nvarchar,@Count1)+'.ID_SaleBill = AAAA1'+convert(nvarchar,@Count1)+'.ID_SaleBill'
- +' Where BBBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And BBBB1'+convert(nvarchar,@Count1)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B1'+convert(nvarchar,@Count1)+' On B1'+convert(nvarchar,@Count1)+'.ID_Product = D1'+convert(nvarchar,@Count1)+'.ID_Product '
-
- +' Left Join( Select AAA1'+convert(nvarchar,@Count1)+'.ID_Product, CCC1'+convert(nvarchar,@Count1)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA1'+convert(nvarchar,@Count1)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB1'+convert(nvarchar,@Count1)+' On BBB1'+convert(nvarchar,@Count1)+'.ID_SaleBill = AAA1'+convert(nvarchar,@Count1)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC1'+convert(nvarchar,@Count1)+' On CCC1'+convert(nvarchar,@Count1)+'.No_FromBill = BBB1'+convert(nvarchar,@Count1)+'.No_SaleBill And CCC1'+convert(nvarchar,@Count1)+'.No_FromBillProduct = AAA1'+convert(nvarchar,@Count1)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD1'+convert(nvarchar,@Count1)+' On DDD1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill = CCC1'+convert(nvarchar,@Count1)+'.ID_SaleRtnBill'
- +' And DDD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD1'+convert(nvarchar,@Count1)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' Where BBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill > DateAdd(yy,-1,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB1'+convert(nvarchar,@Count1)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BBB1'+convert(nvarchar,@Count1)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C1'+convert(nvarchar,@Count1)+' On C1'+convert(nvarchar,@Count1)+'.ID_Product = D1'+convert(nvarchar,@Count1)+'.ID_Product '
- End
-
- Set @Count1 = @Count1 + 1
- Fetch Next From Cur1 Into @DataBase_Company
- End
- Close Cur1
- Deallocate Cur1
- Set @sql9 = @sql9 +' ) A1 Group By A1.ID_Product'
- Set @sql9 = @sql9 +' ) OneY On OneY.ID_Product = P.ID_Product'
- Declare @Count4 int
- Set @Count4 = 0
- declare @sql4 nvarchar(4000)
- set @sql4 = ''
- declare @sql10 nvarchar(4000)
- set @sql10 = ''
- Set @sql4 = @sql4 + ' Left Join( Select ID_Product,(Sum(Quantity_SaleAmount)-Sum(IsNull(Quantity_SaleBillProduct,0))+Sum(IsNull(Quantity_SaleRtnBillProduct,0))) As ThreeM_SaleAmount From ('
- Declare Cur4 Cursor for Select DataBase_Company From [SunRoxmManager].dbo.Company Where ShortName_Company In (select * from [SunRoxmManager].[dbo].[Temp])
- Open Cur4
- Fetch Next From Cur4 Into @DataBase_Company
- While @@Fetch_Status = 0
- Begin
-
- If(@Count4 = 0)
- Begin
- Set @sql4 = @sql4 +' Select D4'+convert(nvarchar,@Count4)+'.ID_Product,D4'+convert(nvarchar,@Count4)+'.Quantity_SaleAmount,B4'+convert(nvarchar,@Count4)+'.Quantity_SaleBillProduct,C4'+convert(nvarchar,@Count4)+'.Quantity_SaleRtnBillProduct From ('
- +' Select AA4'+convert(nvarchar,@Count4)+'.ID_Product, (IsNull(AA4'+convert(nvarchar,@Count4)+'.Quantity_SaleBillProduct,0)- IsNull(CC4'+convert(nvarchar,@Count4)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA4'+convert(nvarchar,@Count4)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB4'+convert(nvarchar,@Count4)+' On BB4'+convert(nvarchar,@Count4)+'.ID_SaleBill = AA4'+convert(nvarchar,@Count4)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC4'+convert(nvarchar,@Count4)+' On CC4'+convert(nvarchar,@Count4)+'.No_FromBill = BB4'+convert(nvarchar,@Count4)+'.No_SaleBill And CC4'+convert(nvarchar,@Count4)+'.No_FromBillProduct = AA4'+convert(nvarchar,@Count4)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD4'+convert(nvarchar,@Count4)+' On DD4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill = CC4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill'
- +' And DD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And DD4'+convert(nvarchar,@Count4)+'.ID_Assessor Is Not Null'
- +' Where BB4'+convert(nvarchar,@Count4)+'.ID_Assessor Is Not Null '
- +' And BB4'+convert(nvarchar,@Count4)+'.Date_SaleBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB4'+convert(nvarchar,@Count4)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BB4'+convert(nvarchar,@Count4)+'.IsImport_SaleBill = 0) D4'+convert(nvarchar,@Count4)
-
- +' Left Join (Select AAAA4'+convert(nvarchar,@Count4)+'.ID_Product,AAAA4'+convert(nvarchar,@Count4)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA4'+convert(nvarchar,@Count4)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB4'+convert(nvarchar,@Count4)+' On BBBB4'+convert(nvarchar,@Count4)+'.ID_SaleBill = AAAA4'+convert(nvarchar,@Count4)+'.ID_SaleBill'
- +' Where BBBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And BBBB4'+convert(nvarchar,@Count4)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B4'+convert(nvarchar,@Count4)+' On B4'+convert(nvarchar,@Count4)+'.ID_Product = D4'+convert(nvarchar,@Count4)+'.ID_Product '
-
- +' Left Join( Select AAA4'+convert(nvarchar,@Count4)+'.ID_Product, CCC4'+convert(nvarchar,@Count4)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA4'+convert(nvarchar,@Count4)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB4'+convert(nvarchar,@Count4)+' On BBB4'+convert(nvarchar,@Count4)+'.ID_SaleBill = AAA4'+convert(nvarchar,@Count4)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC4'+convert(nvarchar,@Count4)+' On CCC4'+convert(nvarchar,@Count4)+'.No_FromBill = BBB4'+convert(nvarchar,@Count4)+'.No_SaleBill And CCC4'+convert(nvarchar,@Count4)+'.No_FromBillProduct = AAA4'+convert(nvarchar,@Count4)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD4'+convert(nvarchar,@Count4)+' On DDD4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill = CCC4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill'
- +' And DDD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' Where BBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BBB4'+convert(nvarchar,@Count4)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C4'+convert(nvarchar,@Count4)+' On C4'+convert(nvarchar,@Count4)+'.ID_Product = D4'+convert(nvarchar,@Count4)+'.ID_Product '
- End
- If(@Count4 > 0)
- Begin
- Set @sql10 = @sql10 + ' Union All Select D4'+convert(nvarchar,@Count4)+'.ID_Product,D4'+convert(nvarchar,@Count4)+'.Quantity_SaleAmount,B4'+convert(nvarchar,@Count4)+'.Quantity_SaleBillProduct,C4'+convert(nvarchar,@Count4)+'.Quantity_SaleRtnBillProduct From ('
- +'Select AA4'+convert(nvarchar,@Count4)+'.ID_Product, (IsNull(AA4'+convert(nvarchar,@Count4)+'.Quantity_SaleBillProduct,0)- IsNull(CC4'+convert(nvarchar,@Count4)+'.Quantity_SaleRtnBillProduct,0)) As Quantity_SaleAmount'
- +' From [' + @DataBase_Company + '].DBO.SaleBillProduct AA4'+convert(nvarchar,@Count4)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BB4'+convert(nvarchar,@Count4)+' On BB4'+convert(nvarchar,@Count4)+'.ID_SaleBill = AA4'+convert(nvarchar,@Count4)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CC4'+convert(nvarchar,@Count4)+' On CC4'+convert(nvarchar,@Count4)+'.No_FromBill = BB4'+convert(nvarchar,@Count4)+'.No_SaleBill And CC4'+convert(nvarchar,@Count4)+'.No_FromBillProduct = AA4'+convert(nvarchar,@Count4)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DD4'+convert(nvarchar,@Count4)+' On DD4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill = CC4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill'
- +' And DD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And DD4'+convert(nvarchar,@Count4)+'.ID_Assessor Is Not Null'
- +' Where BB4'+convert(nvarchar,@Count4)+'.ID_Assessor Is Not Null '
- +' And BB4'+convert(nvarchar,@Count4)+'.Date_SaleBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BB4'+convert(nvarchar,@Count4)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BB4'+convert(nvarchar,@Count4)+'.IsImport_SaleBill = 0) D4'+convert(nvarchar,@Count4)
-
- +' Left Join (Select AAAA4'+convert(nvarchar,@Count4)+'.ID_Product,AAAA4'+convert(nvarchar,@Count4)+'.Quantity_SaleBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAAA4'+convert(nvarchar,@Count4)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBBB4'+convert(nvarchar,@Count4)+' On BBBB4'+convert(nvarchar,@Count4)+'.ID_SaleBill = AAAA4'+convert(nvarchar,@Count4)+'.ID_SaleBill'
- +' Where BBBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' And BBBB4'+convert(nvarchar,@Count4)+'.IsImport_SaleBill = 1 And Disable_SaleBill = 1 ) B4'+convert(nvarchar,@Count4)+' On B4'+convert(nvarchar,@Count4)+'.ID_Product = D4'+convert(nvarchar,@Count4)+'.ID_Product '
-
- +' Left Join( Select AAA4'+convert(nvarchar,@Count4)+'.ID_Product, CCC4'+convert(nvarchar,@Count4)+'.Quantity_SaleRtnBillProduct From [' + @DataBase_Company + '].DBO.SaleBillProduct AAA4'+convert(nvarchar,@Count4)
- +' Left Join [' + @DataBase_Company + '].DBO.SaleBill BBB4'+convert(nvarchar,@Count4)+' On BBB4'+convert(nvarchar,@Count4)+'.ID_SaleBill = AAA4'+convert(nvarchar,@Count4)+'.ID_SaleBill'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBillProduct CCC4'+convert(nvarchar,@Count4)+' On CCC4'+convert(nvarchar,@Count4)+'.No_FromBill = BBB4'+convert(nvarchar,@Count4)+'.No_SaleBill And CCC4'+convert(nvarchar,@Count4)+'.No_FromBillProduct = AAA4'+convert(nvarchar,@Count4)+'.No_SaleBillProduct'
- +' Left Join [' + @DataBase_Company + '].DBO.SaleRtnBill DDD4'+convert(nvarchar,@Count4)+' On DDD4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill = CCC4'+convert(nvarchar,@Count4)+'.ID_SaleRtnBill'
- +' And DDD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And DDD4'+convert(nvarchar,@Count4)+'.Date_SaleRtnBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
- +' Where BBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill > DateAdd(mm,-3,'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39) +') '
- +' And BBB4'+convert(nvarchar,@Count4)+'.Date_SaleBill <'+nchar(39)+convert(nvarchar,@DateTime)+nchar(39)
-
- +' And BBB4'+convert(nvarchar,@Count4)+'.IsImport_SaleBill = 1 And Disable_SaleRtnBill = 1 ) C4'+convert(nvarchar,@Count4)+' On C4'+convert(nvarchar,@Count4)+'.ID_Product = D4'+convert(nvarchar,@Count4)+'.ID_Product '
- End
-
- Set @Count4 = @Count4 + 1
- Fetch Next From Cur4 Into @DataBase_Company
- End
- Close Cur4
- Deallocate Cur4
- Set @sql10 = @sql10 +' ) A4 Group By A4.ID_Product'
- Set @sql10 = @sql10 +' ) ThreeM On ThreeM.ID_Product = P.ID_Product'
- declare @sql5 nvarchar(4000)
- set @sql5 = ''
- Set @sql5 = @sql5 + ' Left Join ('
- +' Select M.ID_Product,NotArrive_Amount,Quantity_OnShip From('
- +' Select ID_Product,Sum(NotArrive_Amount) As NotArrive_Amount,Sum(Quantity_OnShip) As Quantity_OnShip '
- +' From ('
- +' Select ta.ID_PurchaseOrderBill,ta.ID_Product,(IsNull(ta.Quantity_PurchaseOrderBillProduct,0)-IsNull(ta.Quantity_InDepot,0)-IsNull(ta.Quantity_OnShip,0)) As NotArrive_Amount,IsNull(ta.Quantity_OnShip,0) As Quantity_OnShip'
- +' From ( Select b.ID_PurchaseOrderBill,b.ID_Product, sum(a.Quantity_Order) As Quantity_PurchaseOrderBillProduct,sum(a.Quantity_InDepot) As Quantity_InDepot,sum(a.Quantity_OnShip) As Quantity_OnShip,sum(a.Quantity_EndCase) As Quantity_EndCase,(sum(a.Quantity_Order)-sum(a.Quantity_InDepot)-sum(a.Quantity_OnShip)-sum(a.Quantity_EndCase)) As NoInDepot'
- +' From PurchaseSourceBillProduct a'
- +' Join PurchaseOrderBillProduct b On a.ID_PurchaseSourceBillProduct=b.ID_PurchaseOrderBillProduct'
- +' Group By b.ID_Product ,b.ID_PurchaseOrderBill'
- +' Having (sum(a.Quantity_Order)-sum(a.Quantity_InDepot)-sum(a.Quantity_EndCase)) > 0'
- +' )ta'
-
- +' ) A5 Group By A5.ID_Product )M'
-
- +' ) SQ On SQ.ID_Product = P.ID_Product'
- Declare @sql6 nvarchar(4000)
- set @sql6 = ''
- set @sql6 = @sql6 + ' Left Join ('
- +' Select ta.ID_Product,PurchaseOrderBill.No_PurchaseOrderBill,RefNo_PurchaseOrderBill,Comment_PurchaseOrderBillProduct,(IsNull(ta.Quantity_PurchaseOrderBillProduct,0)-IsNull(ta.Quantity_InDepot,0)-IsNull(ta.Quantity_OnShip,0)) As PNotArrive_Amount,IsNull(ta.Quantity_OnShip,0) As PQuantity_OnShip'
- +' From'
- +' ( Select b.ID_PurchaseOrderBill,b.ID_Product, sum(a.Quantity_Order) As Quantity_PurchaseOrderBillProduct,sum(a.Quantity_InDepot) As Quantity_InDepot,sum(a.Quantity_OnShip) As Quantity_OnShip,sum(a.Quantity_EndCase) As Quantity_EndCase,(sum(a.Quantity_Order)-sum(a.Quantity_InDepot)-sum(a.Quantity_OnShip)-sum(a.Quantity_EndCase)) As NoInDepot'
- +' From PurchaseSourceBillProduct a'
- +' Join PurchaseOrderBillProduct b On a.ID_PurchaseSourceBillProduct=b.ID_PurchaseOrderBillProduct'
- +' Group By b.ID_Product ,b.ID_PurchaseOrderBill'
- +' Having (sum(a.Quantity_Order)-sum(a.Quantity_InDepot)-sum(a.Quantity_EndCase)) > 0'
- +' )ta'
- +' Join Product On Product.ID_Product=ta.ID_Product'
- +' Join PurchaseOrderBillProduct On PurchaseOrderBillProduct.ID_PurchaseOrderBill = ta.ID_PurchaseOrderBill And PurchaseOrderBillProduct.ID_Product = ta.ID_Product'
- +' Join PurchaseOrderBill On PurchaseOrderBill.ID_PurchaseOrderBill=ta.ID_PurchaseOrderBill'
- +' Where PurchaseOrderBill.ID_Assessor Is Not Null '
- +' ) po On po.ID_Product = P.ID_Product'
- +' Left Join (Select ID_Product,Sum(StockQty_ProductStocks) As StockQty_ProductStocks From ProductStocks Group By ID_Product) ps On PS.ID_Product = P.ID_Product'
- +' Left Join Product On Product.ID_Product = P.ID_Product'
- +' Order By No_Product,No_PurchaseOrderBill'
- EXEC (@sql+@sqlP+@sql3+@sql7 +@sql2+@sql8+ @sql1+@sql9+@sql4+@sql10+@sql5+@sql6)
-
- drop table [SunRoxmManager].[dbo].[Temp]">
- <Params>
- <Param name="@sqlCompany" type="PurchaseInDepotBill.Comment_PurchaseInDepotBill" Index="0" />
- <Param name="@DateTime" type="SaleBill.Date_SaleBill" Index="1" />
- </Params>
- <Tables>
- <Table name="Get" />
- <Table name="FrmYearSalesStatistics"/>
- </Tables>
- </SearchYearSalesStatistics>
- </Search>
- </Server>
- </Form>
- </Forms>
|