使用Charindex选择全部或参数 [英] Select all or parameter with Charindex

查看:93
本文介绍了使用Charindex选择全部或参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中根据列表框中的条目提取以下查询,我不能对此数据源使用存储过程。



选择*来自事件charindex(','+ events.AcctNumber +',',','+ @AcctNumber +',')> 0和(@StartDate和@EndDate之间的事件日期)



我怎么写这个,所以如果@Acctnumber为空,它会选择@StartDate和@EndDate之间的ALL记录

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

推荐答案

只需输入一个OR。

Just put an OR into it.
Select * From events Where (charindex(',' + events.AcctNumber + ',', ',' + @AcctNumber + ',')>0 OR @AcctNumber = '') and (eventdate Between @StartDate and @EndDate)


这篇关于使用Charindex选择全部或参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆