开发者

How to make grid results show "<" rather than "&lt;"?

开发者 https://www.devze.com 2023-02-07 04:35 出处:网络
This code: SomeField + \' <\' + cast(count(AnotherField) as varchar(6)) + \'>\' Generates the following result in the grid view:

This code:

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

Generates the following result in the grid view:

Blah &lt;Blah2&gt;

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


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


Not a perfect solution, but I works...

REPLACE(REPLACE(MyTable.MyColumn, '&lt;', '<'),'&gt;', '>') AS MyColumn

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

0

精彩评论

暂无评论...
验证码 换一张
取 消