2

我在存储过程中使用了以下选择语句:

SELECT DISTINCT Name, BugID, Summary, Description, reportedDate, versionID, versionName, BugResolution, IssueStatusId, BugStatus, BugType, BugPriority, ComponentName, ReportedBy, 
STUFF(( SELECT ',' + Comment 
                  FROM lbbugnet.dbo.report_view I Where I.bugID= O.bugID
                FOR
                  XML PATH('')
                ), 1, 1, '') as Comment, 
    Code, IssueResolutionId FROM lbbugnet.dbo.report_view O
    WHERE BugID BETWEEN @fromID AND @toID
    ORDER BY BugID ASC

这会选择需要的列并将注释填充到同一列而不是单独的记录中。因为值被转换为 XML 文本

<p></p>

已更改为

&lt;p&gt;&lt;/p&gt;,

有什么办法可以防止这种情况发生或在选择后将其更改回来?

4

1 回答 1

1
SELECT DISTINCT
    Name, 
    BugID, 
    Summary, 
    Description, 
    reportedDate, 
    versionID, 
    versionName, 
    BugResolution, 
    IssueStatusId, 
    BugStatus, 
    BugType, 
    BugPriority, 
    ComponentName, 
    ReportedBy,
    Comment.value('.', 'varchar(max)') Comments,
    Code, 
    IssueResolutionId       
FROM   
    (SELECT 
        Name, BugID, Summary, Description, reportedDate, versionID, versionName, BugResolution, IssueStatusId, BugStatus, BugType, BugPriority, ComponentName, ReportedBy,
        CAST(STUFF(( SELECT ',' + Comment 
                      FROM lbbugnet.dbo.report_view I Where I.bugID= O.bugID
                    FOR
                      XML PATH('')
                    ), 1, 1, '') as xml) as Comment,
        Code, IssueResolutionId         
    FROM 
      lbbugnet.dbo.report_view O
    WHERE 
      BugID BETWEEN @fromID AND @toID) A
ORDER BY 
    BugID ASC
于 2013-08-01T11:08:21.403 回答