Data Loader

MSSQL STR function and it's equivalent in MySQL.

The STR function in MS SQL Server is used to convert numeric values to character strings. It's syntax is given below


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


Is an expression of approximate numeric (float) data type with a decimal point.

Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.

Is the number of places to the right of the decimal point. decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point.



The following query converts a number 12345.67890 to string value and also rounds the number to 3 decimal places

select STR(12345.67890,12,3)
STR function in MSSQL


In MySQL the same functionality can be achieved by using CAST function. The CAST function will convert numeric value
 to character string. If you also want to round the number to N decimal places as in MSSQL then you have to use ROUND
function also.


mysql> select CAST(12345.67890 as CHAR);
| CAST(12345.67890 as CHAR) |
| 12345.67890 		    |
1 row in set (0.00 sec)
mysql> select cast(round(12345.67890,3) as char);
| cast(round(12345.67890,3) as char) |
| 12345.679 |
1 row in set (0.02 sec)

MSSQL STR function equivalent in MySQL

Back to Converting Functions from MSSQL to MySQL