如何让网格结果显示“<”而不是“<”?

发布于 2024-10-13 19:38:20 字数 733 浏览 2 评论 0 原文

此代码:

SomeField + ' <' + cast(count(AnotherField) as varchar(6)) + '>'

在网格视图中生成以下结果:

Blah &lt;Blah2&gt;

如何确保 HTML 实体显示为其等效字符?我很惊讶我无法找到谷歌答案。

谢谢。

这是一个更大的片段:

select
   stuff((
      select
         ', ' + SomeField + ' <' + cast(count(AnotherField) as varchar(6)) + '>'
      from
         SomeTable as SomeAbbrev
      where
         SomeField = SomeOutsideField
      group by
         SomeField
      order by
         SomeField asc
      for xml path('')
   ),1,1,'') SomeFields
from
   blablabla
inner join
   blablabla
left join
   blablabla
left join
   blablabla
order by
   SomeDateField asc

This code:

SomeField + ' <' + cast(count(AnotherField) as varchar(6)) + '>'

Generates the following result in the grid view:

Blah <Blah2>

How can I ensure the HTML entities show as their character equivalents? I'm surprised I wasn't able to find a Google answer.

Thanks.

Here's a larger snippet:

select
   stuff((
      select
         ', ' + SomeField + ' <' + cast(count(AnotherField) as varchar(6)) + '>'
      from
         SomeTable as SomeAbbrev
      where
         SomeField = SomeOutsideField
      group by
         SomeField
      order by
         SomeField asc
      for xml path('')
   ),1,1,'') SomeFields
from
   blablabla
inner join
   blablabla
left join
   blablabla
left join
   blablabla
order by
   SomeDateField asc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失去的东西太少 2024-10-20 19:38:20

您可以在此处查看所使用的技术,或者一起绕过 XML 技术可能会更简单并尝试类似下面的示例。

此示例返回所有表及其列作为逗号分隔字符串。

create function dbo.ColumnString(@table_id int)
returns nvarchar(max)
as
begin
    declare @x nvarchar(max)

    select @x = coalesce(@x+',','') + c.name
        from sys.columns c
        where c.object_id = @table_id
        order by c.name

    return @x
end
go

select t.name, dbo.ColumnString(t.object_id)
    from sys.tables t
    where t.type = 'U'
    order by t.name

drop function dbo.ColumnString

You can look at the technique used here or it may be simpler to bypass the XML technique all together and try something like the example below.

This example returns all tables with their columns as a comma delimited string.

create function dbo.ColumnString(@table_id int)
returns nvarchar(max)
as
begin
    declare @x nvarchar(max)

    select @x = coalesce(@x+',','') + c.name
        from sys.columns c
        where c.object_id = @table_id
        order by c.name

    return @x
end
go

select t.name, dbo.ColumnString(t.object_id)
    from sys.tables t
    where t.type = 'U'
    order by t.name

drop function dbo.ColumnString
乞讨 2024-10-20 19:38:20

这不是一个完美的解决方案,但我可以...

REPLACE(REPLACE(MyTable.MyColumn, '<', '<'),'>', '>') AS MyColumn

使用 UDF 替换 html 代码列表可能是更“干净”的解决方案。

Not a perfect solution, but I works...

REPLACE(REPLACE(MyTable.MyColumn, '<', '<'),'>', '>') AS MyColumn

Using a UDF to replace a list of html codes could be a little more "clean" solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文