SQL Server:在case语句中将UniqueIdentifier转换为字符串 [英] SQL Server: converting UniqueIdentifier to string in a case statement
问题描述
我们有一个日志表,该表的消息列有时具有异常堆栈跟踪.我有一些确定邮件是否包含此条件的条件.我们不想向客户显示这些消息,而是显示类似这样的消息:
We have a log table that has a message column that sometimes has an exception stack trace. I have some criteria that determines if the message has this. We do not want to show these messages to the customer but instead have a message like:
发生内部错误.联系我们 带有参考代码 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Internal Error Occured. Contact US with reference code xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
其中xxx etc是表中的guid列.我正在这样写存储过程:
where xxx etc is a guid column in the table. I am writing stored proc like this:
declare @exceptionCriteria nvarchar(50)
select @exceptionCriteria = '%<enter criteria etc>%'
select LogDate,
case
when Message like @exceptionCriteria
then 'Internal Error Occured. Reference Code: ' + str(RequestID)
else Message
end
from UpdateQueue
RequestID
是SQL Server中的Guid数据类型,此处不会转换为字符串.我已经看到了一些有关如何将Guid转换为字符串的代码,但是它是多行的,我认为它在case语句中不起作用.有什么想法吗?
RequestID
is a Guid datatype in SQL Server and does not convert to string here. I've seen some code on how to convert a Guid to string, but it is multi-lined and I don't think it would work in a case statement. Any ideas?
推荐答案
我想我找到了答案:
convert(nvarchar(50), RequestID)
这是我找到此信息的链接:
Here's the link where I found this info:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
这篇关于SQL Server:在case语句中将UniqueIdentifier转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!