zoukankan      html  css  js  c++  java
  • 扩大范围的多条件查询

    代码
    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
  • 相关阅读:
    php提取字符串中的数字
    php中urlencode()和urldecode()URL编码函数浅析[转]
    B2C电子商务系统研发——商品SKU分析和设计(一)
    电商ERP系统——商品SKU与库存设计
    爬虫实战:爬虫之 web 自动化终极杀手 ( 上)
    鸟瞰前端 , 再论性能优化
    反-反爬虫:用几行代码写出和人类一样的动态爬虫
    小巧玲珑:机器学习届快刀XGBoost的介绍和使用
    从零开始接入腾讯云智能推荐
    云技术平台赋能媒体融合发展创新
  • 原文地址:https://www.cnblogs.com/xnxylf/p/1732235.html
Copyright © 2011-2022 走看看