cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SQL "Replicate" Function

millicentdark
Contributor
0 Likes
832

Hi Experts,

Is there another function that works exactly like SQL "REPLICATE" function?

Regards

Justice

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member186605
Active Contributor
0 Likes
Hi Justice, check also Lars Breddemann in
kothandaraman_nagarajan
Active Contributor
0 Likes

Hi,

Replicate function is working in SQL server. For example, if you run below query,

SELECT REPLICATE( ' Nagarajan ' , 2 )

Result is, Nagarajan Nagarajan

Thanks

millicentdark
Contributor
0 Likes

Hi Diego,

My SQL has the replicate function. What is happening is I want an alternative to this function because I used it to created a query in SAP Business UDF query and it works perfectly.

Unfortunately SAP Business One version for HANA does not have the replicate function and became of that I can't apply the query in the UDF query .

If there's an alternative function that also works in both SAP Business one version for SQL and HANA I will be glad if that can be shared .

Regards

Justice

Former Member
0 Likes

Hi Justice,

Sorry, I still not know hana.

Good Luck.


Best regards,

Diego Lother


View Diego Lother's profile on LinkedIn

Former Member
0 Likes

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


View Diego Lother's profile on LinkedIn