CHAPTER 2
Single-Table Queries
71
The
FORMAT
Function
The FORMAT function allows you to format an input value as a character string based on a Microsoft
.NET format string and an optional culture.
Syntax
FORMAT(input , format_string, culture)
There are numerous possibilities for formatting inputs using both standard and custom format
strings. The MSDN article at http://go.microsoft.com/fwlink/?LinkId=211776 provides more informa-
tion. But just as a simple example, recall the convoluted expression used earlier to format a number
as a 10-digit string with leading zeros. By using FORMAT, you can achieve the same task with either
the custom form string ‘0000000000’ or the standard one, ‘d10’. As an example, the following code
returns ‘0000001759’.
SELECT FORMAT(1759, '000000000');
Do'stlaringiz bilan baham: |