The REPLICATE function returns a string by replicating a string value a specified number of times. This function is usually used to format outputs.
In MySQL the same functionality is provided by REPEAT function. Here the examples of both MSSQL and MySQL
REPLICATE ( string_expression ,integer_expression )
select REPLICATE('0',4); -------------- 0000
select REPLICATE('0',5-datalength(rtrim(productid)))+CAST(productid as varchar) ,ProductID from Production.Product order by ProductID
(No column name) ProductID 00001 1 00002 2 00003 3 00004 4 00316 316 00317 317 00318 318
In the MySQL the REPEAT function offers the same results. Here is the example
REPEAT(str,count)
mysql> select repeat('#',4); +---------------+ | repeat('#',4) | +---------------+ | #### | +---------------+ 1 row in set (0.00 sec) mysql>
Assuming that same PRODUCT table is existing in MySQL also, then giving the following query gives the following result
select concat(repeat('0',5-char_length(productid)),productid) from product
Back to Converting Functions from MSSQL to MySQL