请问我想要在5,6个约束条件的情况下绑定gridview,因为有5,6个约束条件,因此我不想根据字段的空或者不空写很多的select语句,我想传参数的时候,把空与不空的值都传给select语句中的where子句,这样的话就只需要写一条select语句就能全部解决了!但是如何在字段为空的时候,写出where 字段名=“全体值”的这种情况?如果可以的话,我可以先用if语句赋变量为全体值!一起传值过去。
之前想的是where 字段名=*,但是不能通过。
哪位高手能给解决下哈?谢谢了!
之前想的是where 字段名=*,但是不能通过。
哪位高手能给解决下哈?谢谢了!
{
sql += " and name='"+name+"'";
}
//.....
UP 注意 and前面的空格
{
strSQL += "这个条件"}
create proc p_selectBy
@where1 varcahr(5),
@where2 varcahr(5),
@where3 varcahr(5),
...
as
declare @sqlwhere varchar(5000)
set @sqlwhere ='1=1'
if(@where1 is not null && @where1 <>'')
set @sqlwhere =@sqlwhere +' and column1='+@where1
if(@where2 is not null && @where1 <>'') set @sqlwhere =@sqlwhere +' and column2='+@where2
if...
{
sql += " and name='"+name+"'";
}
这个不错