Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 When Parameter is be null?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

117 Posts

Posted - 08/11/2008 :  17:37:15  Show Profile  Reply with Quote
Hi all,
I know it may seem funny for you but I am really confused right now.
I have a select like this:
SELECT CaseID, CaseIDText, IntakeWorkerID
FROM dbo.tbl_Case
WHERE (CaseID = @Param1) AND (CaseIDText = @Param2)

Sometimes user may not enter a value for @param2 how can I handle it in my code. I think I should use like statement but I don’t know how.
I should use this code in my application.
Please help me.


Almighty SQL Goddess

38200 Posts

Posted - 08/11/2008 :  17:43:02  Show Profile  Visit tkizer's Homepage  Reply with Quote
Use the COALESCE function to handle it in the WHERE clause.

WHERE CaseID = COALESCE(@Param1, CaseID) AND CaseIDText = COALESCE(@Param2, CaseIDText)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server

Subscribe to my blog
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 08/12/2008 :  03:04:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote

WHERE (CaseID = @Param1 or @Param1 is null) AND (CaseIDText = @Param2 or @Param2 is null)


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000