STR () function in SQL

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.