[英]Replace parts of a string in sql
我有一列包含以下格式的字符串:
Account Number [1.######] belongs to customer [2.########] residing in [3.######] for the selected period.
我想用来自表格的实际值替换 1、2 和 3 的占位符。
如下所示:
Account Number 1234 belongs to John residing in London for the selected period.
任何帮助将不胜感激。
提前致谢。
问候,拉姆
从 SQL Server 2016 开始,它支持FORMATMESSAGE()
函数的增强版本。
消息最多可包含 2,047 个字符。
这是一个概念性的例子。
SQL
DECLARE @message VARCHAR(2048) = 'Account Number %s belongs to customer %s residing in %s for the selected period.';
DECLARE @AccountNo VARCHAR(20) = '1234'
, @Customer VARCHAR(20) = 'John'
, @Location VARCHAR(20) = 'London'
, @Result VARCHAR(2048);
SET @Result = FORMATMESSAGE(@message
, @AccountNo
, @Customer
, @Location);
-- test
SELECT @Result;
输出
Account Number 1234 belongs to customer John residing in London for the selected period.
在您的选择语句中添加以下内容:
[New Field] = CONCAT('Account ',table.field,' belongs to customer ',table.field,'residing in 'table.field' for theselected period.')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.