订货单_查看_下一笔.sql 3.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. exec sp_executesql N' DECLARE @ID_IndentBill uniqueidentifier
  2. DECLARE @IndentBillNo nvarchar(64)
  3. SELECT TOP 1 @IndentBillNo = IndentBill.No_IndentBill FROM IndentBill
  4. Join Customer On Customer.ID_Customer=IndentBill.ID_Customer
  5. WHERE IndentBill.No_IndentBill > @No_IndentBill
  6. And Customer.ID_Creator=case IsNull(DataLength(@Right),0) When 0 Then Customer.ID_Creator Else @Right End --added for validating right
  7. and Special_IndentBill=case @Special when 1 then Special_IndentBill else 0 End --added for Special
  8. and Customer.ID_RegionalLeader in
  9. (Select ID_RegionalLeader From Principal
  10. Where ID_Employee in(select ID_Employee from Employee where Name_Employee=@Name_Employee)
  11. )
  12. ORDER BY IndentBill.No_IndentBill
  13. SELECT IndentBill.*, Customer.No_Customer, Customer.Name_Customer, Customer.ShortName_Customer, Customer.Type_Customer,
  14. Customer.LastDiscount_Customer, Customer.PostalCode_Customer,
  15. a.Name_User AS Name_Creator, ISNULL(b.Name_User, '''') AS Name_Assessor, ISNULL(c.Name_User, '''') AS LastModUserName,
  16. Location.No_Location, Location.Name_Location, Employee.No_Employee AS No_Principal ,Employee.Name_Employee AS Principal_IndentBill
  17. FROM IndentBill
  18. LEFT JOIN Customer ON Customer.ID_Customer = IndentBill.ID_Customer
  19. LEFT JOIN AppUser a ON a.ID_User = IndentBill.ID_Creator
  20. LEFT JOIN AppUser b ON b.ID_User = IndentBill.ID_Assessor
  21. LEFT JOIN AppUser c ON c.ID_User = IndentBill.LastModUser_IndentBill
  22. LEFT JOIN Location ON Location.ID_Location = IndentBill.ID_Location
  23. LEFT JOIN Employee ON Employee.ID_Employee = IndentBill.ID_Principal
  24. WHERE IndentBill.No_IndentBill = @IndentBillNo
  25. SELECT @ID_IndentBill = IndentBill.ID_IndentBill FROM IndentBill WHERE IndentBill.No_IndentBill = @IndentBillNo
  26. SELECT IndentBillProduct.*, Product.No_Product, Product.Name_Product, Product.Unit_Product,
  27. Product.LowSalePrice_Product, BillType.Name_BillType,
  28. (IndentBillProduct.Quantity_IndentBillProduct * IndentBillProduct.UnitPrice_IndentBillProduct) AS Amount_IndentBillProduct,@IndentBillNo as No_IndentBill
  29. FROM IndentBillProduct
  30. LEFT JOIN Product ON Product.ID_Product = IndentBillProduct.ID_Product
  31. LEFT JOIN BillType ON BillType.Value_BillType = IndentBillProduct.Type_FromBill
  32. WHERE IndentBillProduct.ID_IndentBill = @ID_IndentBill ORDER BY CAST(IndentBillProduct.No_IndentBillProduct AS INT)
  33. SELECT BillComment.* FROM BillComment WHERE BillComment.ID_Bill = @ID_IndentBill order by BillComment.No_BillComment
  34. SELECT ReportComment.*,@IndentBillNo as No_IndentBill FROM ReportComment WHERE ReportComment.ID_Bill = @ID_IndentBill order by ReportComment.No_ReportComment',N'@No_IndentBill nvarchar(64),@Right uniqueidentifier,@Special bit,@Name_Employee nvarchar(64)',@No_IndentBill=N'I1904010001',@Right=NULL,@Special=1,@Name_Employee=N'1111'