Search code examples
stored-proceduressap-ase

Database stored procedure create string based on format string like sprintf


Sybase ASE has a format-string based print statement:

print 'some value: %1!, some other value: %2!, info: %3!, @val1, @val2, @val3 

I would like to create VARCHAR-information in the same manner, but I can't manage to find a function which allows to do this as conveniently. It seems the only option is to concatenate the results of CONVERT() functions.

Is there similar functionality not for printing but for writing to variables?


Solution

  • I think, this not any so function.

    Use:

    SET @str = REPLACE(REPLACE(REPLACE( 'some value: %1!, some other value: %2!, info: %3!', '%1', @val1 ),  '%2', @val2), '%3', @val3)