我有两种
select * from t_Customer where (cSourName =@cSourName or @cSourName is null or @cSourName = '' ) and ( cValueName =(@cValueName) or @cValueName is null or @cValueName = '' ) and ( cRankName =(@cRankName) or @cRankName is null or @cRankName = '' ) and (cTypeName = (@cTypeName)or @cTypeName is null or @cTypeName = '' )
跟
exec ('select * from t_Customer as cus,t_User as u where cus.cUserID=u.cUserID and cSourName in ('+@cSourName+') and cValueName in ('+@cValueName+') and cRankName in ('+@cRankName+') and cTypeName in ('+@cTypeName+')
第一种只能实现一个参数传递,第二种如果有空的查询,就只能查询带空的记录。大家看看有没什么好的办法。我想实现的效果是,我选中一些checkbox的时候,
select * from t_customer where cSourName in ('百度推广', '朋友介绍') and cValueName in ('')当cValueName 传如的值为空的时候,只需查询前面的cSourName 条件的所有数据。
select * from t_Customer where (cSourName =@cSourName or @cSourName is null or @cSourName = '' ) and ( cValueName =(@cValueName) or @cValueName is null or @cValueName = '' ) and ( cRankName =(@cRankName) or @cRankName is null or @cRankName = '' ) and (cTypeName = (@cTypeName)or @cTypeName is null or @cTypeName = '' )
跟
exec ('select * from t_Customer as cus,t_User as u where cus.cUserID=u.cUserID and cSourName in ('+@cSourName+') and cValueName in ('+@cValueName+') and cRankName in ('+@cRankName+') and cTypeName in ('+@cTypeName+')
第一种只能实现一个参数传递,第二种如果有空的查询,就只能查询带空的记录。大家看看有没什么好的办法。我想实现的效果是,我选中一些checkbox的时候,
select * from t_customer where cSourName in ('百度推广', '朋友介绍') and cValueName in ('')当cValueName 传如的值为空的时候,只需查询前面的cSourName 条件的所有数据。
解决方案 »
- json的输出~~
- 为什么我的DLL文件总不能被覆盖?
- 2.0中怎样在页面上才会生成__doPostBack()方法????
- 求大哥们帮帮忙!关于一个方法。。。。请进来看看
- ascx与aspx的区别的疑问
- aspnet 怎么得到动态添加控件的值
- DataGrid的DataSource在每次提交以后都成了null,如何保存住DataSource呢?
- 事务中执行3个存储过程,2条insert语句,谁有例子,谢谢!
- jquery 或js拖拽插入的问题
- UTF8转GB2312部分出现乱码!注意,是部分!
- 怎么实现修改数据库数据,能即时弹出提示
- C#中 问个土的问题,我想把系列数据保存下来,到另外个窗体里调用
declare @sql nvarchar(max)
declare @sqlwhere varchar(500)
set @sqlwhere = '条件'set @sql = '你的sql'if(@cTypeName<>'')
begin
set @sql += @sqlwhere
end
....