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 |
|
Sep410
Posting Yak Master
117 Posts |
Posted - 2008-08-11 : 17:37:15
|
| 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, IntakeWorkerIDFROM dbo.tbl_CaseWHERE (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 vb.net application.Please help me.Sep |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-11 : 17:43:02
|
| Use the COALESCE function to handle it in the WHERE clause.WHERE CaseID = COALESCE(@Param1, CaseID) AND CaseIDText = COALESCE(@Param2, CaseIDText)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-12 : 03:04:44
|
| orWHERE (CaseID = @Param1 or @Param1 is null) AND (CaseIDText = @Param2 or @Param2 is null)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|