Wrox Programmer Forums
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 03:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Stored Procedure

Hello,

I have 2 params. There are 4 situations, one where both param1 and param2 are not null, where one of param1 or param2 is null and the other isn't, or where both are null. Is there a simple way of querying based on this instead of writing four separate queries?

Thanks,

Brian
__________________
Brian
 
Old October 7th, 2004, 08:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is there any default value specified for those params?

Try using COALESCE function to achieve that.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 8th, 2004, 03:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Vijay is right, you just need to give both params a default value of NULL and then COALESCE away the defaults, like this
...
WHERE Field1 = COALESCE(@param1, Field1)
AND Field2 = COALESCE(@param2, Field2)

then if either of the params are not supplied (i.e. = NULL) they effectively get ignored.

rgds
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
Stored Procedure jezywrap SQL Server ASP 1 January 3rd, 2007 12:29 AM
stored procedure kdm260 SQL Server 2000 2 June 19th, 2006 04:45 PM
Stored Procedure rajanikrishna SQL Server 2000 0 July 18th, 2005 05:01 AM
Help About Stored Procedure zhuge6 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 May 20th, 2005 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.