SP_Cust_PDA_GetItemMasterBarCodes.sql 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- ================================================
  2. -- Template generated FROM Template Explorer using:
  3. -- Create Procedure (New Menu).SQL
  4. --
  5. -- Use the Specify Values for Template Parameters
  6. -- command (Ctrl-Shift-M) to fill IN the parameter
  7. -- values below.
  8. --
  9. -- This block of comments will NOT be included IN
  10. -- the definition of the procedure.
  11. -- ================================================
  12. SET ANSI_NULLS ON
  13. GO
  14. SET QUOTED_IDENTIFIER ON
  15. GO
  16. -- =============================================
  17. -- Author: 曹嘉杰
  18. -- Create date: 2022/10/17
  19. -- Description: 查询料品条码信息
  20. -- =============================================
  21. IF (EXISTS (SELECT * FROM SYS.OBJECTS WHERE NAME = 'SP_Cust_PDA_GetItemMasterBarCodes'))
  22. DROP PROC SP_Cust_PDA_GetItemMasterBarCodes
  23. GO
  24. CREATE PROCEDURE SP_Cust_PDA_GetItemMasterBarCodes
  25. -- Add the parameters for the stored procedure here
  26. @ItemCode NVARCHAR(255),
  27. @ProjCode NVARCHAR(255),
  28. @SeibanNo NVARCHAR(50),
  29. @PageSize INT,
  30. @PageIndex INT
  31. AS
  32. BEGIN
  33. -- SET NOCOUNT ON added to prevent extra result sets FROM
  34. -- interfering with SELECT statements.
  35. SET NOCOUNT ON;
  36. -- Insert statements for procedure here
  37. --IF OBJECT_ID('tempdb..#TempBarCodes') IS NOT NULL
  38. --BEGIN
  39. -- DROP TABLE #TempBarCodes
  40. --END
  41. SELECT BarCode.Code AS BarCode,
  42. BarCode.Segment80 AS PartName,
  43. CASE WHEN (SUBSTRING(Code, 1, 1) = 'C' AND LEN(Code) = 16) THEN SUBSTRING(Code, 1, 9) + '_' + SUBSTRING(Code, 12, 5) ELSE SUBSTRING(Code, 1, LEN(Code) - 5) END AS PackageCode
  44. INTO #TempBarCodes
  45. FROM BC_BarCode AS BarCode
  46. INNER JOIN BC_BarCodeRuleLine AS RuleLine ON RuleLine.BarCodeRule = BarCode.BarCodeRule AND RuleLine.SegmentValue='Project.Code' AND RuleLine.SegmentSeq = 5
  47. WHERE Segment1 = @ItemCode
  48. AND Segment2 = @SeibanNo
  49. AND Segment5 = @ProjCode
  50. AND WhQty > 0
  51. INSERT INTO #TempBarCodes
  52. SELECT BarCode.Code AS BarCode,
  53. BarCode.Segment80 AS PartName,
  54. CASE WHEN (SUBSTRING(Code, 1, 1) = 'C' AND LEN(Code) = 16) THEN SUBSTRING(Code, 1, 9) + '_' + SUBSTRING(Code, 12, 5) ELSE SUBSTRING(Code, 1, LEN(Code) - 5) END AS PackageCode
  55. FROM BC_BarCode AS BarCode
  56. INNER JOIN BC_BarCodeRuleLine AS RuleLine ON RuleLine.BarCodeRule = BarCode.BarCodeRule AND RuleLine.SegmentValue='Project.Code' AND RuleLine.SegmentSeq = 6
  57. WHERE Segment1 = @ItemCode
  58. AND Segment2 = @SeibanNo
  59. AND Segment6 = @ProjCode
  60. AND WhQty > 0
  61. SELECT * FROM #TempBarCodes
  62. END
  63. GO
  64. EXEC SP_Cust_PDA_GetItemMasterBarCodes @ItemCode = N'11019999-00006', @SeibanNo = N'11000000023', @ProjCode = N'RD01', @PageSize = 15, @PageIndex = 1