sql-server – SQL Server printf
|
在Sql Server中是否有类似printf的功能?我想要与RAISERROR功能相同的功能,但是我不想抛出错误或打印消息,而是将其写入varchar,因为我的ERP不会让我处理错误消息. 这是SQL Server 2000. RAISERROR的实际工作示例: declare @name varchar(10)
set @name = 'George'
RAISERROR ('Hello %s.',10,1,'George')
打印你好乔治 我正在寻找: declare @name varchar(10),@message varchar(50)
set @name = 'George'
SET @message = printf('Hello %s.','George')
return @message
这将返回你好乔治 解决方法如果您的格式字符串数量有限,并且可以将它们添加到sysmessages(通过 sp_addmessage),则可以使用 FORMATMESSAGE:
以下是SQL Server 2005或更高版本的有效答案,但不幸的是,OP正在为SQL Server 2000寻求解决方案: 这是丑陋的,滥用Try / Catch和RAISERROR: declare @message varchar(50)
begin try
RAISERROR('Hello %s',16,'george')
end try
begin catch
set @message = ERROR_MESSAGE()
end catch
print @message (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
