473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parameterized Query Performance Help!

5
I am having trouble with paramterized query. This will end up being a stored procedure in the end, but for now I am working with it in Query Analyzer.

DECLARE

@Tax_ID varchar(9)
@Badge_ID varchar(9)

SET @Tax_ID = '1234'
SET @Badge_ID = '5678'

Select * from Test where tax_id = @Tax_ID and badge_id = @Badge_ID


-This executes and returns 17 records in 1 second


However, the user may choose one or all parameters. So, I need to check for NULL.

Select * from Test where tax_id = ISNULL(@Tax_ID, tax_id) and badge_id = ISNULL(@Badge_ID,badge_id)


-This executes and returns 17 records in almost 2 MINUTES!!!

The table is indexed by Tax_ID and Badge_ID.

Looking at the Execution Plan reveals that it is doing a clustered index scan.
How can I optimize the query without doing a bunch of structured IF..ELSEIF statements? I also tried using the COALESCE function, but it did not improve the speed.


TIA
Don
Oct 11 '06 #1
1 2016
I normally write:
Expand|Select|Wrap|Line Numbers
  1. Select * from Test
  2.  where (tax_id = @tax_id or ISNULL(@Tax_ID, '')='') 
  3.  and (badge_id = @badge or ISNULL(@Badge_ID,'')='')
any better?
Hi
Fausto
Oct 13 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: gary b | last post by:
Hello When I use a PreparedStatement (in jdbc) with the following query: SELECT store_groups_id FROM store_groups WHERE store_groups_id IS NOT NULL AND type = ? ORDER BY group_name
8
by: deko | last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of new to parameterized queries, so I'm sure I'm missing something simple. Set qdfs = db.QueryDefs Set qdf =...
2
by: deko | last post by:
Is it possible to build a parameterized query from another parameterized query? I've tried two variations of this and can't seem to get it to work (using DAO). Any suggestions welcome! I...
2
by: Stig Nielsson | last post by:
I am wondering what is the most efficient way to make a parameterized factory method, and before I start spending time on performance measurements myself, I would like to hear the NG's opinion: ...
11
by: anony | last post by:
Hello, I can't figure out why my parameterized query from an ASP.NET page is dropping "special" characters such as accented quotes & apostrophes, the registered trademark symbol, etc. These...
2
by: JSheble | last post by:
After building a parameterized ADO query, is there a method or a statement where you could see the actual query, with the parameterized values included?? -- Using Opera's revolutionary e-mail...
2
by: tranceport185 | last post by:
I have ASP strSQL = "SELECT POSCat.Description , InnerJoinCategoryReport.Total"_ & "FROM POSCat LEFT JOIN InnerJoinCategoryReport ON InnerJoinCategoryReport.Cat = POSCat.Description " ...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
2
by: weird0 | last post by:
i write query in this manner by contatenting a string: cmd.CommandText = "SELECT acc_name FROM Account_Information where user_id='" + User_Id + "'"; Is there any other way to do it.... ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.