Wednesday, March 13, 2013

SQL Server STR Function

In this post , I will explain the STR function of SQL Server of string functions category.
In my previous posts, I explained SPACE, SUBSTRING, UPPER, STUFF, LEN and other string functions of  SQL Server. You can also find some other articles related to SQL Server.

Here, I am going to explain STR function of SQL Server.


STR() Function

This function returns character data converted from numeric data. It takes 3 arguments. First argument as float data,second argument as integer value specifying the length of the string including decimal that is to be retrieved and third argument as integer specifying the number of places to the right of the decimal point.
 
Syntax- STR(float_expression [ , length [ , decimal ] ])
Arguments-
  • float_expression : An expression of approximate numeric (float) data type with a decimal point.
  • length : An integer value specifying the length of the string including decimal that is to be retrieved.
  • float_expression : An integer specifying the number of places to the right of the decimal point.
Return Type- char


Example-
 
SELECT STR(123.45, 6, 1)
--Output 123.5

When the expression exceeds the specified length, the string returns ** for the specified length.

SELECT STR(123.45, 2, 2)
--Output **

No comments:

Post a Comment

^ Scroll to Top