Hope someone can help. I am trying to pad a zero infront of any result that has under 10 digits in column GPF4. The column GPF4 is designed to be Numeric(18,0) as later on I will be converting this number into Hexidecimal with reversed pairs. result comes with no changes
here is the code to try and pad the zero infront
UPDATE Filter_All
SET GPF4 = RIGHT(CONVERT(varchar(10), REPLICATE('0', 10 - LEN(GPF4)) + CONVERT(varchar(10), GPF4)) + CONVERT(varchar(10), GPF4), 10)
WHERE LEN(GPF4) < 10
actual number 821295578 in GPF4
expected result 0821295578
Resulted with 821295578 (no changes)
I tired again, this time sucessfull howerever the result was padded with the last digit from the of the affected row in GPF4
UPDATE Filter_All
SET GPF4 = RIGHT(CONVERT(varchar(10), REPLICATE('0', 10 - LEN(GPF4)) + CONVERT(varchar(10), GPF4)) + CONVERT(varchar(10), GPF4), 10)
WHERE LEN(GPF4) < 10
- actual number 821295578 in GPF4
- expected result 0821295578
- Resulted with 8821295578
here is the code to try and pad the zero infront
UPDATE Filter_All
SET GPF4 = RIGHT(CONVERT(varchar(10), REPLICATE('0', 10 - LEN(GPF4)) + CONVERT(varchar(10), GPF4)) + CONVERT(varchar(10), GPF4), 10)
WHERE LEN(GPF4) < 10
- actual number 821295578 in GPF4
- expected result 0821295578
- Resulted with 821295578 (no changes)
I tired again, this time sucessfull howerever the result was padded with the last digit from the of the affected row in GPF4
UPDATE Filter_All
SET GPF4 = RIGHT(CONVERT(varchar(10), REPLICATE('0', 10 - LEN(GPF4)) + CONVERT(varchar(10), GPF4)) + CONVERT(varchar(10), GPF4), 10)
WHERE LEN(GPF4) < 10
- actual number 821295578 in GPF4
- expected result 0821295578
- Resulted with 8821295578
Try using concatenation as follows:
The above example provides an output with GPF4 and padded GPF4
You can try same logic in update statement.