1

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?

Beginner
  • 5,277
  • 6
  • 34
  • 71

1 Answers1

1

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)
garik
  • 5,669
  • 5
  • 30
  • 42
  • Thanks! this works if I use str_replace (its ASE not IQ). – Beginner Mar 31 '17 at 12:56
  • @Beginner is it still T-SQL? +1 – garik Mar 31 '17 at 13:38
  • I am not sure why REPLACE does not work but str_replace does, but i am not the only one, see for example here: http://stackoverflow.com/questions/6547383/is-there-any-function-like-replace – Beginner Mar 31 '17 at 15:08
  • 2
    in ASE, the built-in function is STR_REPLACE(). REPLACE does exist but only as a keyword in ALTER TABLE to modify a column's existing default. – RobV Apr 03 '17 at 09:57