What are differences and similarities between CharIndex, patindex?

730    Asked by IsaacRoss in SQL Server , Asked on Nov 1, 2019
Answered by Isaac Ross

Replicate function is used to repeat the same string specific number of times, it can replicate a number or a string. It is generally used to create dummy data, insert specific number of zero/ character in between. To get the fixed length of output in increments i.e. 00001, 00203, both are having output as 5 length only.

Syntax: REPLICATE (String_Expression, int_Expression):

String expression: is string which need to replicated

Int expression: will be number of times it need to replicated

Sample: Select REPLICATE ('0', 5) +'1234' AS 'Replicate Output for invoices'


DECLARE @Rep_String VARCHAR(50)

SET @Rep_String = 'Learn SQL Server from JanBask Training '

SELECT REPLICATE ((@Rep_String + ', '), 5) AS 'Replicate Output'



Your Answer

Interviews

Parent Categories