id   mobile   visittime source就这啊!

解决方案 »

  1.   

    我是说你的visittime的数据类型,如果是DATETIME
    select * from 表 where between '2004-12-9' and '2004-12-20'
      

  2.   

    不好意思:
    select * from 表 where visittime between '2004-12-9' and '2004-12-20'
      

  3.   

    select * from 表 where convert(char(10),visittime,120) between '2004-12-09' and '2004-12-20'
      

  4.   

    对年份没有要求啊!
    between是可以,但是要循环出每一天的记录,所以我想到了用while循环
      

  5.   

    set @mydate1 = 3
    while (@mydate1<=20)
    begin
    select * from tblcount where convert(varchar(10),visittime,120) = '2004-12-'+Convert(varchar(2),@mydate1)
    set @mydate1 = @mydate1+1
    end 
    还是不行,不能这样解决么?
      

  6.   

    不要把select * from tblcount ...写进 while 循环,你想啊,那要执行多少次 select 啊,
    每一次select都放在不同的结果集,对你有什么用呢,你怎么看这个数据呢?
      

  7.   

    select * from t where visittime='2004-12-01'
    select * from t where visittime='2004-12-02'
    select * from t where visittime='2004-12-03'
    ---
    select * from t where visittime='2004-12-21'
    该不会说是这样写吗?
    我只是想动态地生成SQL语句,把后面的visittime增而已呀
      

  8.   

    select * from t where visittime='2004-12-01'
    select * from t where visittime='2004-12-02'
    select * from t where visittime='2004-12-03'
    ---
    select * from t where visittime='2004-12-21'
    这样作和
    select * from t where visittime between '2004-12-01' and '2004-12-21' 有什么区别吗?
    在查询分析器里你上面的写法会出现n多个结果集框,后面的把所有结果放在一个框内。你非要用while的话
    while datediff(d,@begindate,@enddate)>=0
    begin
           ---这里放你要做的事情。
           set @begindate=dateadd(d,1,@begindate)
    end
      

  9.   

    select * from 表 where convert(char(10),visittime,120) between '2004-12-09' and '2004-12-20'
      

  10.   

    可以使用游标来实现:
    第一步:创建游标
    DECLARE crr_record CURSOR SCROLL FOR
    SELECT * FROM 表 WHERE visittime BETWEEN '2004-12-09' AND '2004-12-20'
    第二步:使用游标
    declare @c1 类型
    declare @c2 类型
    declare @c3 类型
    OPEN crr_record 
    WHILE @@fetch_status=0
    begin
       fetch next from crr_record into @c1,@c2,@c3
       print @c1,@c2,@c3
    end
    说明:@c1,@c2,@c3为第一、二、三列的值