有什么方法可以优化以下查询?

时间:2017-01-02 09:39:18

标签: sql-server sql-server-2012

只是一个简单的问题,我如何优化我的SQL服务器查询,以及在循环时循环替换的任何方法?...谢谢

DECLARE @TOTAL INT, @COUNT INT=1, @ID INT,@FROMDATE DATE= '2016-11-01', @TODATE= '2016-11-10'
SELECT @TOTAL = COUNT(1) 
FROM NUMBERS  
WHILE @COUNT <= @TOTAL  
BEGIN  
    SELECT @ID = ID 
    FROM #TEMP 
    WHERE ROW_ID = @COUNT  
    DECLARE @OUTPUT VARCHAR(MAX) = '';  
    EXEC SPSAMPLEPROC @ID, @FROMDATE, @TODATE, @OUTPUT OUTPUT; 
    SELECT @COUNT = @COUNT + 1;  
END  

0 个答案:

没有答案