I am working towards migrating an access Right() function onto SQL Server.
This is the Access Right() function:
Barcode: "ID" & (Right(String(8,"0") & [Job Number],8) & Right(String(6,"0") &
[PART LIBARY HEADER_1]![PartID],6) & Right(String(6,"0") & [Part Assembly Link
Table]![AssemblyLinkID],6))
What the above expression does, is that it dynamically creates a field to house a barcode that is always 22 characters in length. Now the values of these barcodes are determined by other columns. I am using the Right() method to gather the Rightmost: 8 chars of Job Number, 6 chars of PartID and 6 chars of AssemblyLinkID.
Now the problem I face is that whilst I can move these values onto T-SQL, I having difficulty setting the default value to be = 0.
For example the following input:
Job Number: 123456
PartID: 9876
AssemblyLinkID: 127
Would need to return… ID00123456009876000127
The String() function in access is handling the null values for me by appending with 0 but this method is not something available in SQL Server.
String(8,"0")
This is my SQL Code so far:
Concat('ID', RIGHT(STR(0, 8) & [Job Number],8)) AS Barcode,
STR() is not the function I am looking to use as it is not giving the same results as MS Access's String().