订货单_查看_下一笔_打印.sql 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. Declare @StartNo nvarchar(64)
  2. Declare @EndNo nvarchar(64)
  3. Declare @Special bit
  4. set @StartNo = 'I1904010002'
  5. set @EndNo = 'I1904010002'
  6. set @Special=1
  7. SELECT IndentBill.*, Customer.No_Customer, Customer.Name_Customer, Customer.ShortName_Customer, Customer.Type_Customer,
  8. Customer.LastDiscount_Customer, Customer.PostalCode_Customer,
  9. a.Name_User AS Name_Creator, ISNULL(b.Name_User, '') AS Name_Assessor, ISNULL(c.Name_User, '') AS LastModUserName,
  10. Location.No_Location, Location.Name_Location, Employee.No_Employee AS No_Principal,Employee.Name_Employee AS Principal_IndentBill,Customer.ID_Creator As CustomerCreator
  11. FROM IndentBill
  12. LEFT JOIN Customer ON Customer.ID_Customer = IndentBill.ID_Customer
  13. LEFT JOIN AppUser a ON a.ID_User = IndentBill.ID_Creator
  14. LEFT JOIN AppUser b ON b.ID_User = IndentBill.ID_Assessor
  15. LEFT JOIN AppUser c ON c.ID_User = IndentBill.LastModUser_IndentBill
  16. LEFT JOIN Location ON Location.ID_Location = IndentBill.ID_Location
  17. LEFT JOIN Employee ON Employee.ID_Employee = IndentBill.ID_Principal
  18. WHERE IndentBill.No_IndentBill >= (case DataLength(@StartNo) when 0 then IndentBill.No_IndentBill else @StartNo end) and IndentBill.No_IndentBill <= (case DataLength(@EndNo) when 0 then IndentBill.No_IndentBill else @EndNo end)
  19. and Special_IndentBill=case @Special when 1 then Special_IndentBill else 0 End --added for Special
  20. SELECT IndentBillProduct.*, Product.No_Product, Product.Name_Product, Product.Unit_Product,
  21. Product.LowSalePrice_Product, BillType.Name_BillType,
  22. (IndentBillProduct.Quantity_IndentBillProduct * IndentBillProduct.UnitPrice_IndentBillProduct ) AS Amount_IndentBillProduct ,IndentBill.No_IndentBill
  23. FROM IndentBillProduct
  24. LEFT JOIN Product ON Product.ID_Product = IndentBillProduct.ID_Product
  25. LEFT JOIN BillType ON BillType.Value_BillType = IndentBillProduct.Type_FromBill
  26. LEFT JOIN IndentBill ON IndentBillProduct.ID_IndentBill = IndentBill.ID_IndentBill
  27. WHERE IndentBill.No_IndentBill >= (case DataLength(@StartNo) when 0 then IndentBill.No_IndentBill else @StartNo end) and IndentBill.No_IndentBill <= (case DataLength(@EndNo) when 0 then IndentBill.No_IndentBill else @EndNo end)
  28. and Special_IndentBill=case @Special when 1 then Special_IndentBill else 0 End --added for Special
  29. ORDER BY CAST(IndentBillProduct.No_IndentBillProduct AS INT)
  30. SELECT ReportComment.*, IndentBill.No_IndentBill
  31. FROM ReportComment
  32. LEFT JOIN IndentBill ON ReportComment.ID_Bill = IndentBill.ID_IndentBill
  33. WHERE IndentBill.No_IndentBill >= (case DataLength(@StartNo) when 0 then IndentBill.No_IndentBill else @StartNo end) and IndentBill.No_IndentBill <= (case DataLength(@EndNo) when 0 then IndentBill.No_IndentBill else @EndNo end)
  34. and Special_IndentBill=case @Special when 1 then Special_IndentBill else 0 End --added for Special
  35. ORDER BY ReportComment.No_ReportComment