Add leading zeros to multiple values and concatenating them

Instead of that code, I wrote this in the SQL server database query browser:

SELECT CONCAT (RIGHT('000'+CAST([ord no] AS int),7), RIGHT('000'+CAST([mdl cnt] AS VARCHAR(3)),3), RIGHT('00'+CAST([PAT POS] AS VARCHAR(3)),2), RIGHT('0000'+CAST([qty] AS VARCHAR(4)),4)) as Barcode
FROM [Table Name].[dbo].[Sheet1$]
WHERE
"Lot No" = 112742
AND
"Bin" = 26

This is also the equivalent code in SQL query Ignition:

SELECT CONCAT (RIGHT('000'+CAST("ord no" AS int),7), RIGHT('000'+CAST("mdl cnt" AS VARCHAR(3)),3), RIGHT('00'+CAST("PAT POS" AS VARCHAR(3)),2), RIGHT('0000'+CAST(qty AS VARCHAR(4)),4)) as Barcode
FROM Sheet1$
WHERE
"Lot No" = 112742
AND
"Bin" = 26

And it worked!!! Now I have the new 16 digits barcode.

2 Likes