Sometimes you need to display a string of characters of a specified length for a column value in a SQL query. To this end, SQL Server supports a function called Replicate() which takes two parameters: the character you want to print and the count (the number of times you want to print the character). The first parameter is the character you want to print and the second is the count up to which you need to print the character.
For example, suppose you need to print an asterisk character (‘*’) some number of times based on a value contained in a Quantity column. Here’s how you can do that:
SELECT Quantity, REPLICATE( '*', Quantity)FROM [Order Details]WHERE Discount IS NOT NULL12 ************10 **********