Note that there are some explanatory texts on larger screens.

plurals
  1. POoptimize SP on sql server 2k5
    primarykey
    data
    text
    <p>I asked a question <a href="https://stackoverflow.com/questions/8883355/query-large-table/8884270#8884270">query large table</a>. This is in response to the same question. There are 4 columns in the <code>where</code> clause. I replaced the cursor with the <code>while</code> loop. But didn't help much. The difference between old and new code is 1 second only. But one thing I noticed. There is one column <code>[col name] varchar(255) allow nulls</code>. If I don't query that column the execution time of new code is half. What can be done to improve the speed? All the columns in the <code>where</code> clause are indexed. Any help is appreciated.</p> <p>while' loop is sample code.</p> <pre><code>declare @temp table (col1 INT PRIMARY KEY, col2 VARCHAR(10), col3 VARCHAR(40), col4 VARCHAR(40) ) INSERT INTO @temp (col1,col2,col3,col4) SELECT col1,col2,SUBSTRING(col3,1,40),col4 FROM dbo.Clients WHERE col5 &lt;&gt; 4 ORDER BY col1 select @from=1,@to=@@rowcout SELECT TOP 1 @col1 = col1,@col2=col2,@col3=col3,@col4=col4 FROM @Temp ORDER BY col1 while @from &lt;= @to begin insert into table2 (....) select ... from table3 where [col name1] = par1 and ([col name2] =par2 or [col name2] = par3] ) --this one takes time insert into table2 (...) select .. from table3 where [col name] like @par1 AND ([col name] like par2 or [col name] like par3) SELECT TOP 1 @col1 = col1,@col2=col2,@col3=col3,@col4=col4 FROM @Temp where col1 &gt; @col1 ORDER BY col1 set @from = @from + 1 end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload