SQL 21:10:02 read 1029 comments 0 font size: large and small subscriptions
STR () function in SQL
Declare @ number smallint
Set @ number = 2
Select cast (replace (STR (@ number, 3), '', '0') as char (3 ))
STR function [String]
Function
Returns the equivalent string of a number.
Syntax
STR (numeric_expression [, length [, decimal])
Parameters
Numeric-expression any approximate number (floating point, real number, or double precision) expression between-1e126 and 1e127.
Length indicates the number of characters to return (including the decimal point, all digits on the right and left of the decimal point, and spaces ). The default value is 10.
Decimal: the number of decimal places to return. The default value is 0.
Usage
If the integer part of A number exceeds the specified length, a string with the specified length but only the asterisk is returned. For example, the following statement returns ***
Select STR (1234.56, 3)
Note:
The maximum length supported is 128. Any length not in the range of 1 to 128 will generate a null result.
Standards and compatibility
*
SQL/92 vendor extension.
*
Reproduced in: http://hi.baidu.com/lslyl/blog/item/16f7d8a9de81bef61f17a201.html
SQL/99 vendor extensions.
*
Sybase is compatible with Adaptive Server Enterprise.
Example
The strings returned by the following statement have a total of 10 characters, with 6 spaces before 1235:
Select STR (0, 1234.56)
The following statement returns result 1234.6:
Select STR (1234.56, 6, 1)