on 2016 Oct 03 6:54 PM
Hi Experts,
Is there another function that works exactly like SQL "REPLICATE" function?
Regards
Justice
Request clarification before answering.
Hi Justice,
With this approach, I just know REPLICATE() function, but if this function is not available in your sql server version, you can build your own function to replicate data.
CREATE FUNCTION myReplicate(@value nvarchar(max), @length int)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @count int = 0
DECLARE @return varchar(MAX) = ''
WHILE(@count < @length)
BEGIN
set @count = @count + 1
set @return = @return + @value
END
RETURN @return
END
And after you create the function in your database, you can call like this:
SELECT dbo.myReplicate('a', 2)
Hope it helps.
Best regards,
Diego Lother
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 59 | |
| 29 | |
| 21 | |
| 11 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.