While working I was looking for a function which can help me to repeat a particular ‘string’ up to ‘n’ number of times and I can dynamically provide the value of ‘n’ and ‘string expression’ to that function as well.
Replicate() fulfills both requirement.
Replicate help us to repeat a string N number of times.
- Example:-
SELECT REPLICATE ('*',10) Result_Set
Result_Set********** - Example:-
DECLARE @v VARCHAR(10) = '*'
DECLARE @v1 INT = 4SELECT REPLICATE (@v,@v1) Result_Set
Result_Set****