Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following query in C# that pulls based on entries in a listbox, I can't use a stored procedure against this datasource.

Select * From events Where charindex(',' + events.AcctNumber + ',', ',' + @AcctNumber + ',')>0 and (eventdate Between @StartDate and @EndDate)

How can I write this so if the @Acctnumber is blank, it would select "ALL" records between the @StartDate and @EndDate
Posted

1 solution

Just put an OR into it.
C#
Select * From events Where (charindex(',' + events.AcctNumber + ',', ',' + @AcctNumber + ',')>0 OR @AcctNumber = '') and (eventdate Between @StartDate and @EndDate)
 
Share this answer
 
Comments
Steve Spittell 19-Nov-15 16:22pm    
Oh gees!, that worked.
ZurdoDev 19-Nov-15 16:27pm    
Glad to hear it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900