Complete the code to format the number 1234.567 to 2 decimal places.
SELECT FORMAT(1234.567, [1]);
The FORMAT function formats a number to the specified number of decimal places. Here, 2 decimal places is correct.
Complete the code to pad the string '42' on the left with zeros to make it 5 characters long.
SELECT LPAD('42', [1], '0');
LPAD pads the string on the left to the total length specified. Here, 5 means the result will be 5 characters long.
Fix the error in the code to pad the string 'abc' on the right with spaces to length 6.
SELECT RPAD('abc', [1], ' ');
RPAD pads the string on the right to the total length specified. To get length 6, use 6.
Fill both blanks to format the number 9876.54321 with 3 decimals and pad the result on the left with '*' to length 12.
SELECT LPAD(FORMAT(9876.54321, [1]), [2], '*');
FORMAT with 3 decimals shows 3 digits after decimal. LPAD pads the formatted string to length 12 with '*'.
Fill all three blanks to pad the string 'data' on the right with '-' to length 10, then format the number 123.456 with 1 decimal place.
SELECT FORMAT(123.456, [1]), RPAD('data', [2], [3]);
FORMAT with 1 decimal shows one digit after decimal. RPAD pads 'data' to length 10 with '-'.