如果 10 个变量之间
ALTER procedure FullSearch(@txtSearch as nvarchar(500),@a1 as bit,@a2 as bit,@a3 as bit,
@a4 as bit,@a5 as bit)
as
begin
if(@a1='true' and @a2='false' and @a3='false' and @a4='false' and @a5='false')
begin
select a1 from b where a1 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='true' and @a3='false' and @a4='false' and @a5='false')
begin
select a2 from b where a2 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='false' and @a3='true' and @a4='false' and @a5='false')
begin
select a3 from b where a3 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='false' and @a3='false' and @a4='true' and @a5='false')
begin
select a4 from b where a4 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='false' and @a3='false' and @a4='false' and @a5='true')
begin
select a5 from b where a5 like '%'+@txtSearch+%'
end
if(@a1='true' and @a2='true' and @a3='false' and @a4='false' and @a5='true')
begin
select a1,a2 from b where a1 like '%'+@txtSearch+%' or a2 like '%'+@txtSearch+%'
end
if(@a1='true' and @a2='false' and @a3='true' and @a4='false' and @a5='true')
begin
select a1,a3 from b where a1 like '%'+@txtSearch+%' or a3 like '%'+@txtSearch+%'
end
if(@a1='true' and @a2='false' and @a3='false' and @a4='true' and @a5='true')
begin
select a1,a4 from b where a1 like '%'+@txtSearch+%' or a4 like '%'+@txtSearch+%'
end
.
.
.
.
end
我在搜索框 a1-a5 到复选框 用户可以选择 a1 和 a2 和 a3 和 a4 和 a5
如果所选字段 a1Í a1 字段 DB 搜索
如果选择字段 a2Ù a2 字段 DB 搜索
如果选择字段 a1,a2Û a1,a2 字段 DB 搜索
如果选择字段 a2,a5Û a2,a5 字段 DB 搜索
如果选择字段 a2,a4,a5? a2,a4,a5 字段 DB 搜索
所有状态检查是否为 5 阶乘,如果使用 a1-a9,则非常非常大
有更简单的方法可以做到这一点。
这是一个可以用任何语言 c、c#、vb 完成的算法
ALTER procedure FullSearch(@txtSearch as nvarchar(500),@a1 as bit,@a2 as bit,@a3 as bit,
@a4 as bit,@a5 as bit)
as
begin
if(@a1='true' and @a2='false' and @a3='false' and @a4='false' and @a5='false')
begin
select a1 from b where a1 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='true' and @a3='false' and @a4='false' and @a5='false')
begin
select a2 from b where a2 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='false' and @a3='true' and @a4='false' and @a5='false')
begin
select a3 from b where a3 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='false' and @a3='false' and @a4='true' and @a5='false')
begin
select a4 from b where a4 like '%'+@txtSearch+%'
end
if(@a1='false' and @a2='false' and @a3='false' and @a4='false' and @a5='true')
begin
select a5 from b where a5 like '%'+@txtSearch+%'
end
if(@a1='true' and @a2='true' and @a3='false' and @a4='false' and @a5='true')
begin
select a1,a2 from b where a1 like '%'+@txtSearch+%' or a2 like '%'+@txtSearch+%'
end
if(@a1='true' and @a2='false' and @a3='true' and @a4='false' and @a5='true')
begin
select a1,a3 from b where a1 like '%'+@txtSearch+%' or a3 like '%'+@txtSearch+%'
end
if(@a1='true' and @a2='false' and @a3='false' and @a4='true' and @a5='true')
begin
select a1,a4 from b where a1 like '%'+@txtSearch+%' or a4 like '%'+@txtSearch+%'
end
.
.
.
.
end
I am in search box a1-a5 to the check box That user can choose a1 and a2 and a3 and a4 and a5
If the selected field a1؛ a1 field DB Search
If the selected field a2؛ a2 field DB Search
If the selected field a1,a2؛ a1,a2 field DB Search
If the selected field a2,a5؛ a2,a5 field DB Search
If the selected field a2,a4,a5؛ a2,a4,a5 field DB Search
All states check by if is 5 factorial that very very very large if use a1-a9
There are easier ways to do this.
This is an algorithm that can be done in any language c,c#,vb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用动态 SQL 并生成句子。查看此链接。请特别注意使用
sp_executesql
部分。类似的东西几乎正是您所需要的。You need to use dynamic SQL and generate the sentence. Check out this link. Pay special attention to section Using
sp_executesql
. Something like that is almost exactly what you need.