Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2002-08-17 : 15:21:19
|
| My indexes seem to be in order. I have index on orderid, propadd andcounty right now. I am considering writing this in dynamic sql. Does anybody have a better way of writing this.(@bring in all input vars@ordernum,....)IF @ordernum IS NULLBEGIN SET @ordernum ='%'ENDIF @propadd IS NULLBEGIN SET @propadd ='%'ENDIF @county IS NULLBEGIN SET @county ='%'ENDIF @city IS NULL OR @city=' 'BEGIN SET @city ='%'ENDIF @state IS NULL OR @state=' 'BEGIN SET @state ='%'ENDIF @zipcode IS NULLBEGIN SET @zipcode ='%'END--********************************************************************--SEARCH COMBINATION--*******************************************************************INSERT INTO @orders (orderid, ordernum, propadd,city,state,zipcode,partyname)SELECT TOP 50 a.orderid, a.ordernum, a.propertyaddress, a.city, a.state, a.zipcode, b.partynameFROM dbo.tblorders aLEFT JOIN dbo.tblparty b ON (a.orderid=b.orderid)WHERE b.primarycust=1AND a.ordernum LIKE @ordernum + '%'AND (a.propertyaddress LIKE @propadd + '%')AND (a.county LIKE @county + '%')AND (a.city LIKE @city + '%')AND (a.state LIKE @state + '%')AND (a.zipcode LIKE + @zipcode + '%')The search is very vast when I search propadd, ordernum or combination but county, city and anything below are very slow. County is indexed. My question is if I use dynamic SQL and trim the where clause to only include selections is this best practice.Thanks in advance.slow down to move faster... |
|
|
r937
Posting Yak Master
112 Posts |
Posted - 2002-08-18 : 10:07:37
|
| dynamic sql is best practice when the situation calls for itas far as the optimizer knows, you could have a LIKE on any of those 6 columns, so the execution plan probably reflects that note: IANAOE (i am not an optimizer expert)the knock against dynamic sql is that it has to be parsed and bound at run time, but if some of the WHERE conditions are missing, the execution plan is going to reflect that and therefore be, um, optimizedgive it a tryrudyhttp://rudy.ca/rudyhttp://rudy.ca/ |
 |
|
|
|
|
|
|
|