select * from 表名 where (药品名=文本框1的值 or 文本框1的值='') or (厂家=文本框2的值 or 文本框2的值='')
不知道你是什么意思,请说明存储过程是用来做什么的,表结构是什么样的?select * from 表名 where 药品名 = 指定的药品名 and 厂家 is null
declare @a varchar(255)--传文本框1 的参数 declare @b varchar(255)--传文本框2 的参数select * from tb where a=case when @a is null or @a='' then a else @a end and b=case when @b is null or @b='' then a else @b end
where (药品名=文本框1的值 or 文本框1的值='')
or (厂家=文本框2的值 or 文本框2的值='')
不知道你是什么意思,请说明存储过程是用来做什么的,表结构是什么样的?select *
from 表名
where 药品名 = 指定的药品名 and 厂家 is null
declare @b varchar(255)--传文本框2 的参数select
*
from
tb
where a=case when @a is null or @a='' then a else @a end
and b=case when @b is null or @b='' then a else @b end
页面拼条件代码,当文本框1里有值,文本框2无值时,就拼成“and 药品名=”+this.文本框1.text,
然后将这个传递给SQL,SQL最好是一个存储过程,里面使用动态SQL先将select语句拼接好,where子句直接写成:where 1=1,虽然这样不是最优化写法。然后将你传递下来的拼在后面,最后exec(动态SQL)就是。
方法2:
有一个文本框就有一个变量,然后将这些变量都传递给SQL,SQL判断如果变量为空则不作为where的条件,不为空则添加到where子句后面。
i do you
end