SP_Cust_PDA_AnalyzeBarCode.sql 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/9/16
  19. -- Description: 查询单头条码信息
  20. -- =============================================
  21. IF (EXISTS (SELECT * FROM SYS.OBJECTS WHERE NAME = 'SP_Cust_PDA_AnalyzeBarCode'))
  22. DROP PROC SP_Cust_PDA_AnalyzeBarCode
  23. GO
  24. CREATE PROCEDURE SP_Cust_PDA_AnalyzeBarCode
  25. -- Add the parameters for the stored procedure here
  26. @BarCode NVARCHAR(500),
  27. @OrgCode NVARCHAR(50)
  28. AS
  29. BEGIN
  30. -- SET NOCOUNT ON added to prevent extra result sets from
  31. -- interfering with SELECT statements.
  32. SET NOCOUNT ON;
  33. -- Insert statements for procedure here
  34. DECLARE @OrgID AS BIGINT
  35. DECLARE @DefaultTableName AS NVARCHAR(50)
  36. DECLARE @Sql AS NVARCHAR(MAX)
  37. SELECT @OrgID = ID FROM Base_Organization WHERE Code = @OrgCode
  38. SELECT @DefaultTableName = DefaultTableName
  39. FROM UBF_MD_Class
  40. WHERE FullName IN (SELECT CreateEntity_EntityType FROM BC_BarCode WHERE Code = @BarCode AND Org = @OrgID AND BarCodeType = 0 AND IsCanceled = 0)
  41. SET @Sql = 'SELECT BarCode.Code AS BarCode, BarCode.CreateEntity_EntityID AS EntityID, BarCode.CreateEntity_EntityType AS EntityType, DefaultTable.DocNo AS DocNo, DefaultTable.WorkFlowID AS FlowID FROM BC_BarCode BarCode'
  42. SET @Sql = @Sql + ' LEFT JOIN ' + @DefaultTableName + ' AS DefaultTable ON DefaultTable.ID = BarCode.CreateEntity_EntityID'
  43. SET @Sql = @Sql + ' WHERE BarCode.Code = ''' + @BarCode + ''' AND BarCode.BarCodeType = 0 AND BarCode.IsCanceled = 0'
  44. EXEC(@Sql)
  45. END
  46. GO
  47. EXEC SP_Cust_PDA_AnalyzeBarCode @BarCode = '110-RCV1102209160005', @OrgCode = '110'