网上订单_查看_下一笔.sql 3.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. exec sp_executesql N' DECLARE @ID_IndentBillOnNet uniqueidentifier
  2. DECLARE @IndentBillOnNetNo nvarchar(64)
  3. SELECT TOP 1 @IndentBillOnNetNo = IndentBillOnNet.No_IndentBillOnNet FROM IndentBillOnNet
  4. Join Customer On Customer.ID_Customer=IndentBillOnNet.ID_Customer
  5. WHERE IndentBillOnNet.No_IndentBillOnNet > @No_IndentBillOnNet
  6. And Customer.ID_Creator=case IsNull(DataLength(@Right),0) When 0 Then Customer.ID_Creator Else @Right End --added for validating right
  7. ORDER BY IndentBillOnNet.No_IndentBillOnNet
  8. SELECT IndentBillOnNet.*, Customer.No_Customer, Customer.Name_Customer, Customer.ShortName_Customer, Customer.Type_Customer,
  9. Customer.LastDiscount_Customer, Customer.PostalCode_Customer, ISNULL(b.Name_User, '''') AS Name_Assessor, Customer.ID_Creator As CustomerCreator,
  10. c.Name_User AS LastModUserName,d.Name_User AS DeleteUserName
  11. FROM IndentBillOnNet
  12. LEFT JOIN Customer ON Customer.ID_Customer = IndentBillOnNet.ID_Customer
  13. LEFT JOIN AppUser b ON b.ID_User = IndentBillOnNet.ID_Assessor
  14. LEFT JOIN AppUser c ON c.ID_User = IndentBillOnNet.LastModUser_IndentBillOnNet
  15. LEFT JOIN AppUser d ON d.ID_User = IndentBillOnNet.DeleteUser_IndentBillOnNet
  16. WHERE IndentBillOnNet.No_IndentBillOnNet = @IndentBillOnNetNo
  17. SELECT @ID_IndentBillOnNet = IndentBillOnNet.ID_IndentBillOnNet FROM IndentBillOnNet WHERE IndentBillOnNet.No_IndentBillOnNet = @IndentBillOnNetNo
  18. SELECT [ID_IndentBillOnNetProduct]
  19. ,[No_IndentBillOnNetProduct]
  20. ,IndentBillOnNetProduct.[ID_IndentBillOnNet]
  21. ,IndentBillOnNetProduct.[ID_Product]
  22. ,[Quantity_IndentBillOnNetProduct]
  23. ,[UnitPrice_IndentBillOnNetProduct]
  24. ,IndentBillOnNet.No_IndentBillOnNet as [Comment_IndentBillOnNetProduct]
  25. ,[Amount_SaleBill],
  26. Product.No_Product, Product.Name_Product, Product.Unit_Product, A.AvailableQty_ProductStocks,
  27. (IndentBillOnNetProduct.Quantity_IndentBillOnNetProduct * IndentBillOnNetProduct.UnitPrice_IndentBillOnNetProduct) AS Amount_IndentBillOnNetProduct ,Price_Product
  28. FROM IndentBillOnNetProduct
  29. LEFT JOIN IndentBillOnNet on IndentBillOnNet.ID_IndentBillOnNet = IndentBillOnNetProduct.ID_IndentBillOnNet
  30. LEFT JOIN Product ON Product.ID_Product = IndentBillOnNetProduct.ID_Product
  31. Left join (Select ID_Product,Sum(AvailableQty_ProductStocks) As AvailableQty_ProductStocks From ProductStocks
  32. Group By ID_Product) A On A.ID_Product = Product.ID_Product
  33. WHERE IndentBillOnNetProduct.ID_IndentBillOnNet = @ID_IndentBillOnNet ORDER BY CAST(IndentBillOnNetProduct.No_IndentBillOnNetProduct AS INT)',N'@No_IndentBillOnNet nvarchar(64),@Right uniqueidentifier',@No_IndentBillOnNet=N'IBN201904010001',@Right=NULL