Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All. My Current Stored Procedure and Function print the barcode bases on State and Apptype. Like below:-

ServiceTypeID|BarCodeID|DataMatrixCode2|DataMatrixCode3|DataMatrixCode4|DataMatrixCode5|DataMatrixCode6|AppType
M|TX300000000421865141|TX300000000421865142|TX300000000421865143|TX300000000421865144|||300|


But now the application size is growing to 13 or 14 pages. So we need to implement the barcode datamatrix in hexadecimal format. So we need to Print either 13 or 14 barcode datamatrix.

State(2)AppType(3)AppID(12)Version(1)TotalPages(1)CurrentPage(1)

Where for total pages >9 will follow hexadecimal format like A = 10, B = 11, C = 12, D = 13, E = 14…

e.g., Custom English application barcode should now look like below:-

AL3000000000001231E1, 1E2,…...,1EB, 1EC, 1ED, 1EE

Please help with some suggestions as to how I can implement the new hexadecimal format?

Here is my Stored Procedure Script:-


SQL
ALTER PROCEDURE [outboundprocess].[usp_GetStagedDailyFulfillmentRecords_Mobility] 

WITH
EXECUTE AS CALLER
AS
BEGIN
	BEGIN TRY
    SET NOCOUNT ON 
	
	SELECT 
	       AT.ServiceTypeID
		  ,[loadfilename]
	      ,[BarCodeID]
		  ,STUFF ( [BarCodeID] , 20 , 1 , 2 )AS DataMatrixCode2
		  ,STUFF ( [BarCodeID] , 20 , 1 , 3 )AS  DataMatrixCode3
		   ,STUFF ( [BarCodeID] , 20 , 1 , 4 )AS  DataMatrixCode4
		  ,CASE WHEN F.primaryState IN ('AK','AR','KY','MI', 'ND', 'WA', 'WV','LA','MS','AL', 'ID', 'OR') AND f.apptypecode IN (300,301,302,303,310,311,312,313,320,321,330,331) 
		  THEN STUFF ( [BarCodeID] , 20 , 1 , 5 ) ELSE
		   CASE WHEN F.primaryState = 'SD' AND f.AppTypeCode IN (301,303,311,313,321,331) THEN STUFF ([BarCodeID] , 20 , 1 , 5) 
           ELSE '' END END  AS DataMatrixCode5
           ,CASE WHEN F.primaryState IN ('AL', 'ID', 'OR') AND f.apptypecode IN (300,301,302,303,310,311,312,313,320,321,330,331) 
           THEN STUFF ( [BarCodeID] , 20 , 1 , 6) ELSE
		   CASE WHEN F.primaryState IN ('LA','MS') AND f.AppTypeCode IN (301,303,311,313,321,331) THEN STUFF ([BarCodeID] , 20 , 1 , 6) 
           ELSE '' END  END AS DataMatrixCode6
		  ,ISNULL(f.[AppTypeCode],'') AS [AppTypeCode]
		  ,ISNULL([LanguageCode],'') AS [LanguageCode]
		  ,ISNULL(f.[FirstName],'') AS [FirstName]
		  ,ISNULL(f.[LastName],'') AS [LastName]
		  ,ISNULL([primaryAddress1],'') AS [ServiceAddress1]
		  ,ISNULL([primaryAddress2],'') AS [ServiceAddress2]
		  ,ISNULL([primaryApartmentNumber],'') AS [ServiceApartmentNumber]
		  ,ISNULL([primaryCity],'') AS [ServiceCity]
		  ,ISNULL([primaryState],'') AS [ServiceState]
		  ,ISNULL([primaryZipCode5],'') AS [ServiceZipCode5]
		  ,ISNULL([primaryZipCode4],'') AS [ServiceZipCode4]
		  ,ISNULL(f.[mailingAddress1],'') AS [BillingAddress1]
		  ,ISNULL(f.[mailingAddress2],'') AS [BillingAddress2]
		  ,ISNULL([mailingApartmentNumber],'') AS [BillingApartmentNumber]
		  ,ISNULL([mailingCity],'') AS [BillingCity]
		  ,ISNULL([mailingState],'') AS [BillingState]
		  ,ISNULL([mailingZipCode5],'') AS [BillingZip5]
		  ,ISNULL([mailingZipCode4],'') AS [BillingZip4]
		  ,ISNULL([ReasonCodes],'') AS [ReasonCodes]
		  ,ISNULL(f.[ContactPhoneNumber],'') AS [PhoneNumber]
		  ,ISNULL([ContactEmailAddress],'') AS [EmailAddress]
		  ,CASE WHEN at.servicetypeid='M' THEN ISNULL([CustomerAccountNumber],'') ELSE
		  ISNULL(InternetAcctNum,'') END AS [CustomerAccountNumber]
		 ,ISNULL([CustomerServiceNumber],'') AS [CustomerServiceNumber]
	  FROM [outboundprocess].[DailyFulfillmentFile] F
	  JOIN dbo.AppTypes AT ON AT.AppTypeID=f.AppTypeCode
	  JOIN dbo.Customers c ON c.CustomerID=f.CustomerID
	WHERE f.loadrowstatus = 'Loaded' AND AT.servicetypeid='M' AND c.ServiceAddressState<>'NV' <pre>



And Here is the Function being Used:-

SQL
ALTER FUNCTION [dbo].[udf_GetBarCodeID] (
	@StateCode char(2),
	@ObjectTypeID int,
	@ApplicationID bigint
)

RETURNS varchar(20)
WITH EXECUTE AS 'dbo'
AS
BEGIN
	
	DECLARE @LanguageID INT,@CustomerID bigint
	DECLARE @ObjectTypeIDString varchar(3) = IsNull(@ObjectTypeID, 0)
	DECLARE @ApplicationIDString varchar(12) = ''
	DECLARE @BarCodeID char(20) = '',@ServiceTypeID CHAR(10),@appType INT
	DECLARE @VerType CHAR(1)
	DECLARE @ServiceType CHAR(1)

	SELECT @ServiceType=at.ServiceTypeID
	
	FROM dbo.Applications a 
	JOIN dbo.AppTypes at ON at.AppTypeID=a.AppType
	WHERE ApplicationID=@ApplicationID	

	SET @ApplicationIDString = Replicate('0', 12- Len(@ApplicationID)) + Convert(varchar(12), @ApplicationID)
	 
	 SELECT @appType=AppType,@CustomerID=CustomerID,@ServiceTypeID=(CASE WHEN AppType IN (300,301,302,303,310,311,312,313,320,321,330,331) 
	 THEN 'M' ELSE 'N' END) ,@VerType=(CASE WHEN AppType IN (300,301,302,303,310,311,312,313,320,321,330,331) 
	 THEN '1' ELSE '2' END)  FROM dbo.Applications WHERE ApplicationID=@ApplicationID

	 SELECT TOP 1 @LanguageID=ISNULL(LanguageID,1) FROM dbo.Customers WHERE @customerID=CustomerID ORDER BY CustomerID desc
	
	
	 
    IF (@objectTypeID Is Null) OR (@objectTypeID ='')
	 or (@StateCode IS NULL) OR (@StateCode ='')
	OR (@ApplicationID is Null)OR (@ApplicationID < 1) --or (@BarCodeSuffix Is Null) 
	  BEGIN
			SET @BarCodeID = 'ErrorCreatingBarCode'
	  END
	ELSE
	  BEGIN
		
		 IF ( @StateCode IN ( 'AL', 'ID', 'OR' )
             AND @ServiceTypeID = 'M'
           )
            OR ( @StateCode IN ( 'LA', 'MS' )
                 AND @ServiceTypeID = 'M'
                 AND @LanguageID = 2
               )
            BEGIN
                SET @BarCodeID = @StateCode + @ObjectTypeIDString
                    + ISNULL(@ApplicationIDString, '') + @VerType+'61';
            END;
        ELSE
            IF ( @StateCode IN ( 'AK', 'AR','WA', 'WV', 'MI', 'KY', 'ND' )
                 AND @ServiceTypeID = 'M'
               )
                OR ( @StateCode IN ( 'LA', 'MS' )
                     AND @ServiceTypeID = 'M'
                     AND @LanguageID = 1
                   )
                OR ( @StateCode IN ( 'SD' )
                     AND @ServiceTypeID = 'M'
                     AND @LanguageID = 2
                   )
                BEGIN
                    SET @BarCodeID = @StateCode + @ObjectTypeIDString
                        + ISNULL(@ApplicationIDString, '') + @VerType+ '51';
                END;
            ELSE
                IF @StateCode IN ('WI','IL') AND @ServiceType='V' AND @ServiceTypeID = 'N'
                    OR ( @StateCode IN ( 'SD' )
                         AND @ServiceTypeID = 'M'
                         AND @LanguageID = 1
                       )
					OR ( @StateCode IN ( 'TX' )
                         AND @ServiceTypeID = 'M'
                        )                       
                    BEGIN
                        SET @BarCodeID = @StateCode + @ObjectTypeIDString
                            + ISNULL(@ApplicationIDString, '') + @VerType+ '41';
                    END;
                ELSE
                    SET @BarCodeID = @StateCode + @ObjectTypeIDString
                        + ISNULL(@ApplicationIDString, '') + @VerType + '31';
		  	  END


	RETURN @BarCodeID
END


What I have tried:

I have tired to Google some suggestions but have not come up with much help.
Posted
Updated 1-May-18 17:40pm

1 solution

If I understand the question correctly, you want to convert the number to hexadecimal format without 0x or leading zeroes.

For this you can use CAST and CONVERT (Transact-SQL) | Microsoft Docs[^] and TRIM (Transact-SQL) | Microsoft Docs[^]

For example to convert 10 it would look like
SQL
SELECT TRIM('0' FROM CONVERT(varchar(max), CONVERT(varbinary(max), 10), 2))

The result is
A
 
Share this answer
 
Comments
SinghK0824 2-May-18 11:40am    
@wendelius Thank you for your help.

Basically if you look at the Barcodes below, I would need to change the 141, 142, 143. 144 TO 1E1, 1E2, 1E3, 1E4 ETC...
TX300000000421865141|TX300000000421865142|TX300000000421865143|TX300000000421865144

But how do I make the change in my stored procedure and the Function?
Wendelius 2-May-18 23:03pm    
Looking at the code

SET @BarCodeID = @StateCode + @ObjectTypeIDString
+ ISNULL(@ApplicationIDString, '') + @VerType + '31';

From which variable the value 141 is coming from?
SinghK0824 9-May-18 16:39pm    
SET @BarCodeID = @StateCode + @ObjectTypeIDString
+ ISNULL(@ApplicationIDString, '') + @VerType + '41';

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900