?
Solved

Where clause in stored procedure

Posted on 2016-09-30
8
Medium Priority
?
69 Views
Last Modified: 2016-09-30
Hello,

 Ihave a where clause in SP ,is a better way of writing this :
WHERE(
					[TravelDate] = @TravelDate OR 
					([TravelDate] is null AND @TravelDate is null) OR
					([TravelDate] is null AND @TravelDate ='') OR
					([TravelDate] ='' AND @TravelDate is null))

Open in new window


Cheers
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 400 total points
ID: 41823323
Hi
Please consider something similar to the following:

WHERE(
					[TravelDate] = @TravelDate OR
					(ISNULL([TravelDate],'') = '' AND ISNULL(@TravelDate,''))
) 

Open in new window

0
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 1600 total points
ID: 41823333
Only need to perform a single test:
WHERE ISNULL([TravelDate],'') = ISNULL(@TravelDate,'')

Open in new window

1
 

Author Closing Comment

by:RIAS
ID: 41823344
Cheers!
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:RIAS
ID: 41823354
Will there be performance difference if I modify the Stored Procedure with

WHERE ISNULL([TravelDate],'') = ISNULL(@TravelDate,'')

Open in new window

?

Cheers
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41823363
I don't think so.
How long took the original solution and how long it takes after you used mine suggestion?
0
 

Author Comment

by:RIAS
ID: 41823367
Can't notice the difference,
Is it worth changing the original code then as I will have to modify nearly 100 Stored Procedures?
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41823377
I guess TravelDate is not indexed, right?
IMO doesn't worth the work. It's mostly code reduction than performance gain.
Take it as code tuning lesson ;)
1
 

Author Comment

by:RIAS
ID: 41823389
Cheers!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question