日期:2014-05-18  浏览次数:20611 次

SQL效率问题
SQL code
Declare @CurrentID int, @JobCode char(10),@Date char(10),@Time char(4)
    BEGIN TRY
        SET @CurrentID = 1;
        Select @JobCode = JobCode,@Date = [Date],@Time = [Time]   
        from Atd_DataReceive
        where DataReceiveId = @CurrentID;
        
        WHILE (@@ROWCOUNT >= 1)
        BEGIN
           UPDATE Atd_DayResult
           SET Time1 = @Time
           WHERE JobCode = @JobCode AND AtdDate = @Date
        SET @CurrentID = @CurrentID + 1; 
        SELECT @JobCode = JobCode,@Date = [Date],@Time = [Time]
        from Atd_DataReceive
        WHERE DataReceiveId = @CurrentID;                 
        END
        COMMIT TRANSACTION
    END TRY

如上代码,当Atd_DataReceive 和Atd_DayResult的数据很多时 这段SQL会很慢 请问有什么办法能增加效率

------解决方案--------------------
SQL code
update a  SET Time1=b.[Time] from Atd_DayResult a,Atd_DataReceive b
where a.JobCode =b.JobCode and a.[Date]=b.[Date]