ASP.NET中的行字符串比较

时间:2016-04-21 21:22:04

标签: asp.net

我继承了一些显示日期事件列表的代码,其中包含开始日期和结束日期。这些值来自SQL db通过存储过程,最终进入aspx页面。

如果某个活动在同一天开始和结束,我不想显示结束日期。尽管已经在视觉上对数据进行了比较,但我尝试使用下面的内联片段实现此操作失败并继续显示EndDate:

<%# (Eval("EDate") == Eval("SDate")) ? "BLANK" : "EndDate" %>

关于我做错的任何建议? 或者我如何在存储过程方面实现这一点?产生这个的代码是:

    SDate =
        CASE 
           WHEN STR(DAY(startdate)) = 1 THEN DATENAME(mm, [StartDate])+' '+LTRIM(STR(DAY(startdate)))+ 'st' + ', ' 
           WHEN STR(DAY(startdate)) =2 THEN DATENAME(mm, [StartDate])+ ' ' +LTRIM(STR(DAY(startdate)))  + 'nd' + ', ' 
           WHEN STR(DAY(startdate)) =3 THEN DATENAME(mm, [StartDate])+ ' ' +LTRIM(STR(DAY(startdate))) + 'rd'+ ', '
           WHEN STR(DAY(startdate)) =21 THEN DATENAME(mm, [StartDate])+ ' ' + LTRIM(STR(DAY(startdate)))  + 'st' + ', ' 
           WHEN STR(DAY(startdate)) =22 THEN DATENAME(mm, [StartDate])+ ' ' +LTRIM(STR(DAY(startdate)))  + 'nd' + ', ' 
           WHEN STR(DAY(startdate)) =23 THEN DATENAME(mm, [StartDate])+ ' ' + LTRIM(STR(DAY(startdate)))+ 'rd'+ ', ' 
           WHEN STR(DAY(startdate)) =31 THEN DATENAME(mm, [StartDate])+ ' ' +LTRIM(STR(DAY(startdate)))  + 'st' + ', '
     ELSE DATENAME(mm, [StartDate])+ ' ' +LTRIM(STR(DAY(startdate)))+ 'th'+ ', ' 
       end,

    EDate =
    CASE 
       WHEN STR(DAY(ENDdate)) = 1 THEN DATENAME(mm, [ENDdate])+' '+LTRIM(STR(DAY(ENDdate)))+ 'st' + ', '
       WHEN STR(DAY(ENDdate)) =2 THEN DATENAME(mm, [ENDdate])+ ' ' +LTRIM(STR(DAY(ENDdate)))  + 'nd' + ', '
       WHEN STR(DAY(ENDdate)) =3 THEN DATENAME(mm, [ENDdate])+ ' ' +LTRIM(STR(DAY(ENDdate))) + 'rd'+ ', '
       WHEN STR(DAY(ENDdate)) =21 THEN DATENAME(mm, [ENDdate])+ ' ' + LTRIM(STR(DAY(ENDdate)))  + 'st' + ', '
       WHEN STR(DAY(ENDdate)) =22 THEN DATENAME(mm, [ENDdate])+ ' ' +LTRIM(STR(DAY(ENDdate)))  + 'nd' + ', '
       WHEN STR(DAY(ENDdate)) =23 THEN DATENAME(mm, [ENDdate])+ ' ' + LTRIM(STR(DAY(ENDdate)))+ 'rd'+ ', '
       WHEN STR(DAY(ENDdate)) =31 THEN DATENAME(mm, [ENDdate])+ ' ' +LTRIM(STR(DAY(ENDdate)))  + 'st' + ', '
 ELSE DATENAME(mm, [ENDdate])+ ' ' +LTRIM(STR(DAY(ENDdate)))+ 'th'+ ', '
   end

0 个答案:

没有答案