2

I need to store generic messages in an SQL Server table, and then get the values and use them within a stored procedure, e.g. "Dear John", where instead of "John" I would like to be able to insert any name obtained within the procedure. In C#, if I stored the text like this: "Dear {0}", I could then easily format it: string.Format(myString, name). Can I do anything like this in SQL Server, other than just REPLACE? I heard something like using CLR in SQL Server, but have no idea whether or how it would work. What is the best way to achieve what I need?

Could you please help?

Thanks.

1
  • What version of SQL Server? Commented Jun 5, 2013 at 14:59

1 Answer 1

2

xp_sprintf may be what you're looking for :

DECLARE @ret_string varchar (255)
EXEC Master.DBO.xp_sprintf @ret_string OUTPUT, '(%s, %s)', 'Hello', 'World'
PRINT @ret_string

Outputs (Hello, World)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.