我用ADO查询记录号为10--30或30--50的记录,语句如何写啊,谢谢!

解决方案 »

  1.   

    cstring strsql="select * from table where (id between 10 and 30) or (id between 30 and 50)";Open((_variant_t)strsql...
    使用_RecordsetPtr的open方法就行了
      

  2.   

    也可以使用>、<号
    between 关键字是包含两头的数据的,比如:
    SELECT title_id, ytd_sales
    FROM titles
    WHERE ytd_sales BETWEEN 4095 AND 12000
    GO下面是结果集:title_id ytd_sales 
    -------- ----------- 
    BU1032   4095        
    BU7832   4095        
    PC1035   8780        
    PC8888   4095        
    TC7777   4095        
    SELECT title_id, ytd_sales      
    FROM titles      
    WHERE ytd_sales > 4095 AND ytd_sales < 12000      
    GO下面是结果集:title_id ytd_sales   
    -------- ----------- 
    PC1035   8780        (1 row(s) affected)
      

  3.   

    cstring strsql="select * from table where (id >=10 and id<=30) or (id >=30 and id<=50)";
      

  4.   

    cstring strsql;
    strsql.format("select *from table where (id<=10 and id<=30) or(id>30 and id<=50");