• 扩大范围的多条件查询


    代码
    declare @TempTab Table(id int,a varchar(50),b varchar(50),c varchar(100));
    insert into @TempTab(id,a,b,c) values(1,'aaa111','bbb111','ccc111');
    insert into @TempTab(id,a,b,c) values(2,'aaa222','bbb222','ccc222');
    insert into @TempTab(id,a,b,c) values(3,'aaa333','bbb333','ccc333');
    insert into @TempTab(id,a,b,c) values(4,'aaa444','bbb444','ccc444');
    insert into @TempTab(id,a,b,c) values(5,'aaa555','bbb555','ccc555');
    select * from @TempTab;

    declare @q_a varchar(50);
    declare @q_b varchar(50);
    declare @q_c varchar(50);
    set @q_a='aaa111';
    set @q_b='bbb222';
    set @q_c='ccc111';
    --set @q_a='aaa111';
    --
    set @q_b='bbb222';
    --
    set @q_c='ccc333';

    declare @count int
    select @count=count(*from @TempTab where a=@q_a and b=@q_b and c=@q_c
    if @count>0
        
    begin
            
    select * from @TempTab where a=@q_a and b=@q_b and c=@q_c
        
    end
    else
        
    begin
            
    select @count=count(*from @TempTab where (a=@q_a and b=@q_bor (a=@q_a and c=@q_cor (b=@q_b and c=@q_c)
            
    if @count>0
                
    begin
                    
    select * from @TempTab where (a=@q_a and b=@q_bor (a=@q_a and c=@q_cor (b=@q_b and c=@q_c)
                
    end
            
    else
                
    begin
                    
    select @count=count(*from @TempTab where a=@q_a or b=@q_b or c=@q_c
                    
    if @count>0
                        
    begin
                            
    select * from @TempTab where a=@q_a or b=@q_b or c=@q_c
                        
    end
                    
    else
                        
    begin
                            
    select * from @TempTab
                        
    end
                
    end
        
    end
    代码
    declare @orgcity varchar(200);
    declare @dstcity varchar(200);
    declare @FromTime DATETIME;
    declare @flightNo varchar(50);
    declare @AirCompanyCode varchar(50);
    declare @CabinType varchar(50);

    set @orgcity='CAN';
    set @dstcity='XIY';
    set @FromTime='2010-05-08 00:00:00:000';
    set @flightNo='cz3208';
    set @AirCompanyCode='cz';
    set @CabinType='u';


    SELECT * FROM SpecialManager where 
    (
    @FromTime between Orgdate and DstDate and orgcity like '%'+@orgcity+'%' and dstcity like '%'+@dstcity+'%' and specialType=0)

    SELECT  top 1 * FROM SpecialManager where (@FromTime between Orgdate and DstDate and orgcity like '%'+@orgcity+'%' and dstcity like '%'+@dstcity+'%' and specialType=0and (flightNo=@flightNo  OR ISNULL(flightNo,'')=''AND (AirCompanyCode=@AirCompanyCode  OR ISNULL(AirCompanyCode,'')=''AND (CabinType like '%'+@CabinType+'%'  OR ISNULL(CabinType,'')=''ORDER BY AirCompanyCode desc,flightNo desc,CabinType desc
  • 相关阅读:
    转!!javaMail使用网易163邮箱报535 Error: authentication failed
    银行卡验证(验证是否存在,卡号类型,归属行)
    Navicat已经成功连接,密码忘记的解决方法
    Inline&IAT Hook原理
    x64dbg尝鲜
    C# 通过Dynamic访问System.Text.Json对象
    dotnet5将asp.net webapi宿主到wpf
    Asp.Net5 MVC with Vue.js
    在 Visual Studio 中使用跟踪点将信息记录到“输出”窗口中
    WPF带阴影的无边框窗体
  • 原文地址:https://www.cnblogs.com/xnxylf/p/1732235.html
Copyright © 2020-2023  润新知