如果 10 个变量之间

发布于 2024-11-24 17:03:01 字数 1875 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

緦唸λ蓇 2024-12-01 17:03:01

您需要使用动态 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文