SELECT *
FROM (
SELECT ll.* ,ROW_NUMBER() OVER ( ORDER BY ll.New DESC,ll.EditTime ) AS RID FROM (
SELECT c.* ,
ct.TypeName AS ''CaseType'' ,
cr.TypeName AS ''ReasonType'',
CASE WHEN
(SELECT MAX(IsLatest) FROM B_Exchange_TB WHERE CaseID = C.CaseID)=2 THEN 1
WHEN (
SELECT COUNT(1) FROM
(SELECT ExchangeID FROM B_ExchangeAnswer_TB WHERE ShowNew=2 AND AnswerType=2) EA
INNER JOIN
(SELECT * FROM B_Exchange_TB)
E ON E.ExchangeID=EA.ExchangeID WHERE E.CaseID=c.CaseID
)>0 THEN 1
ELSE 0
END AS New
FROM ( SELECT C.*
FROM B_Case_TB C
WHERE ( SELECT COUNT(1)
FROM (SELECT * FROM B_Exchange_TB ET WHERE CaseID=C.CaseID) E
INNER JOIN ( SELECT *
FROM dbo.R_ExchSelTeacher_TB '
+ @WhereUser
+ '
) EST ON EST.ExchangeID = E.ExchangeID
WHERE E.CaseID = C.CaseID
) > 0 AND DelFlag = 0 '
+ @WhereCase + '
) c
INNER JOIN ( SELECT LevelTypeID ,
CaseTypeID
FROM dbo.R_LevelType_TB '
+ @WhereLevelType
+ '
) lt ON c.LevelTypeID = lt.LevelTypeID
INNER JOIN ( SELECT CaseTypeID ,
TypeName
FROM dbo.D_CaseType_TB
) ct ON ct.CaseTypeID = lt.CaseTypeID
INNER JOIN ( SELECT ReasonID ,
TypeName
FROM D_CaseReason_TB '
+ @WhereReason + '
) cr ON cr.ReasonID = c.ReasonID )ll
) l
WHERE RID BETWEEN ' + CAST(@startNum AS VARCHAR) + ' AND '
+ CAST(@EndNum AS VARCHAR)
EXEC sp_executesql @Sql
<style type="text/css">
.newflag0{ display:none;}
.newflag1{ color:red;}
</style>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="lnkshowAnswer" runat="server" CommandName="showAnswers" CommandArgument='<%# Eval("ExchangeID") %>' Text='<%# Eval("QuesTitle")%>'></asp:LinkButton>
<asp:Label ID="lblNew" runat="server" Visible="false" Text="New!" ForeColor="Red"></asp:Label>
<span class="newflag<%# Eval("[\"New\"]")%>"><sub>new!</sub></span>
<asp:HiddenField ID="hfAddUserID" runat="server" Value='<%# Eval("AddUserID") %>' />
</td>
<td>
<%# Eval("LoginUserName")%>
</td>
<td>
<%# Eval("AddTime")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>