可以试试不用游标,直接在SELECT里完成。

解决方案 »

  1.   

    用SELECT可以直接拼出字串吗?
      

  2.   


    --try:
    ALTER PROCEDURE [dbo].[SP_GetPHSReturnCheckInfoHTML]AS    declare @RecordID char(10)
        declare @FormNo char(20)
        declare @Applydate char(15)
        declare @Filler char(20)
        declare @Subject char(100)
        declare @Step char(20)
        declare @Dealer char(20)
        declare @Receivedate char(15) 
        declare @HTML varchar(max)    set @HTML=''        select t1.recordid,convert(char(10),t1.applydate,121) as applydate,t1.formno,
            t2.cardnum+t2.chinesename as filler,t1.subject,convert(char(10),t1.receivedate,121) as receivedate,
            case t1.step when 1 then '返廠確認人(核)' when 2 then '廠內接收人(核)' when 3 then '出貨確認人(核)' when 4 then '維修點接收人(辦)' end as step,
            t3.cardnum+t3.chinesename as dealer
    into #
        from p_formstatustab t1,
        incmisdb..person2002_employeeinfotab t2,
        incmisdb..person2002_employeeinfotab t3
        where t1.cardid=t2.cardid and t1.dealpersonid=t3.cardid and t1.formid=109 
        and datediff(d,receivedate,getdate())>10 --and applydate>='2009/3/30'
        order by applydate select @HTML=@HTML+'<tr><td>'+RecordID+'</a></td><td>'+Applydate+'</td><td>'+Filler+'</td><td>'+Subject+'</td><td>'
    +Step+'</td><td>'+Dealer+'</td><td>'+Receivedate+'</td><td></tr>'
    from #
        
        select @HTML as result
    go
      

  3.   

    也可以不用临时表,
    直接select。
    但是那样一句话太复杂,看不清……
      

  4.   

    感觉你掉了个<a>标签。
    select @HTML=@HTML+'<tr><td><a>'+RecordID+'</a></td><td>'+Applydate+'</td><td>'+Filler+'</td><td>'+Subject+'</td><td>'
    +Step+'</td><td>'+Dealer+'</td><td>'+Receivedate+'</td><td></tr>'
    from #
      

  5.   

    貌似你是跨库操作。。datediff(d,receivedate,getdate())>10 
    可改为:
    receivedate<getdate()+10
      

  6.   

    想了想,如果你数据有几千条,
    那么@HTML最后会达到10w甚至更大的长度,
    的确会很慢。建议你做适当拆分,或重新设计一下思路。
    弄个几千行的table没有很大实际意义,
    页面估计基本加载不了。
      

  7.   

    1.建议分页。
    2.将数据展现到页面一般不这么整,
    而是用gridview,datalist,repeater等绑定数据库相应字段。