all groups > sql server mseq > june 2006 >
You're in the

sql server mseq

group:

Speed Up QueryTime


Speed Up QueryTime Nishant Giri
6/25/2006 10:27:01 PM
sql server mseq: Hi i am using sql 2000 . i am searching all the records into the database,
for this i have used the 'Like %' in my query ..For Example
Select * from table1
WHERE Col1 Like '%'

But the response time of this query is very high . How can i reducde the
responsetime of the query , Is there any way to avoid this 'Like %' Operator
so that i can search all the records and also reduce the response time .
Re: Speed Up QueryTime Arnie Rowland
6/26/2006 7:49:12 AM
You do not want to use 'LIKE '%". That causes the server to have to =
needlessly read each and every value.Also, you SHOULD list each column =
you want to retreive. Using SELECT * may cause you undesired problems in =
the future.

Here are a couple of choices:

1. NO where clause

SELECT=20
Column1
, Column2
, Column3
, etc
FROM MyTable

2. Where clause with the option to search for a value or get all rows if =
there is no value.

SELECT=20
Column1
, Column2
, Column3
, etc
FROM MyTable
WHERE SearchColumn =3D coalesce( @MySearchField, SearchColumn)

In the second example, you can pass in a search parameter =
@MySearchField, and if it is not NULL, it will be used to retreive =
matching data. If it is NULL, then all rows will be returned (subject to =
other search criteria, of course.)

--=20
Arnie Rowland, YACE*=20
"To be successful, your heart must accompany your knowledge."

*Yet Another Certification Exam


[quoted text, click to view]
..
AddThis Social Bookmark Button