SQL Server Articles

Submit Article
Home » Articles » SQL Server » String FunctionsRSS Feeds

STR Function

Posted By: Sarita Patel     Category: SQL Server     Views: 3822

This article explains the use of STR function in sql server with example.

STR function is used to convert numeric value to character. 

Syntax of STR Function :

STR ( float_expression [ ,length [ ,decimal ] ] )

float_expression is an expression of float data type with a decimal point.

length is total length including decimal point, sign, digits, and spaces. The default is 10. If you specify negative value then it returns NULL. It should be greater than or equal to the part of the number before the decimal point plus it's sign. If it is not so then it returns ** .

decimal is the number of places after decimal point. If you specify negative value then it returns NULL.

Return type of STR function is char.

Examples of STR function :

Example 1 : Use of STR function in select clause

SELECT STR(137.45,7,3)  


Above example can displays 6 digits and a decimal point as seventh character. Fractional part of the number is rounded to three decimal places. 

Example 2 : Converting negative number to character type using STR function

SELECT STR(-137.45,6,1)  


Above example displays 4 digits, 5th character as negative sign and 6th character as decimal point. Fractional part of the number is rounded to one decimal place.



Didn't find what you were looking for? Find more on STR Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of STR Function is from United States.
View All Articles

Related Articles and Code:

Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

No Comment Found, Be the First to post comment!