select a.员工号,a.卡号,b.划卡日期,count(b.划卡时间)
from 员工表 a,划卡记录表 b
where a.卡号=b.卡号
group by a.员工号,a.卡号,b.划卡日期

解决方案 »

  1.   

    create proc test
    @begindate datetime(20)
    @enddate   datetime(20)
    as
    select a.员工号,a.卡号,b.划卡日期,count(b.划卡时间)
     into #temp from 员工表 a,划卡记录表 b
    where (a.卡号=b.卡号)and(b.划卡开始日期〈=@begindate AND b.划卡结束日期〉=@ENDDATE)set @a =(select count(*) from #temp where (a.卡号=b.卡号)and(b.划卡开始日期〈=@begindate AND b.划卡结束日期〉=@ENDDATE)
    print '@a'
      

  2.   

    : microlong(微龙)没明白我的意思,
    我是希望求某一天,员工表中的所有员工划卡次数,并要的到所有划卡时间如: while @i<=划卡次数
         begin
           set @划卡时间 = 划卡时间
         ....对 @划卡时间 进行处理   
         end
      

  3.   

    不用循环的!
    select  员工号, 卡号,划卡日期,划卡时间 from 员工表,划卡记录表
    where 员工表。卡号=划卡记录表。卡号
    这样不行吗??
      

  4.   

    to : windljf(挣扎中。。) 那我怎么取每条记录的"划卡时间"并对它处理
      

  5.   

    to  windljf(挣扎中。。) 象你那样写,我怎么取每条记录的 "划卡时间" 并处理
      

  6.   

    create proc test
    @empID  int,
    @indate datetime(20),
    @times int output
    as
    set nocount onselect a.员工号,b.划卡日期,count(b.划卡时间) as times
    into #temp from 员工表 a left outer join 划卡记录表 b on a.卡号=b.卡号
    where b.划卡日期=@indate and a.员工号=@empIDselect  @times=times from #tempif @times<=划卡次数
      begin
      
    SELECT DISTINCT 划卡时间
    FROM 划卡记录表 
    Where  b.划卡日期=@indate and a.员工号=@empID

      end
      

  7.   

    to leimin(黄山光明顶)
    你的好象有问题吧
    Yang_(扬帆破浪), newly_ignorant(不学无术) N_chow(一剑飘香++) 
    jinfeng_wang(G-G-S,D-D-U) 
    诸位高手,你们在哪里啊
      

  8.   

    to leimin(黄山光明顶)
    你那是个if语句,不能遍历划卡记录表中的所有划卡时间
      

  9.   

    to newly_ignorant(不学无术)
    前两条都对
    第三条,我需要把指定日期的员工 的所有划卡时间作处理,因此好象只有作一个循环,在循环中把划卡时间赋予一个变量,然后对变量处理
    比如  一个员工当天划了5次卡,则循环次数为5,然后在每次循环中读当前记录的划卡时间到一变量中,对变量处理后,再进如下次循环,当该员工所有划卡时间处理完后,退出循环,再处理下一个员工。
      

  10.   

    类似这样的结果吗员工   是否划卡 划卡次数 划卡时间
    01     Y         3        8点
    01     Y         3        9点
    01     Y         3        10点
    02     Y         1        8点
      

  11.   

    抱歉,我不会了,找高手吧,我是菜鸟,呵呵SQLServer还没重装呢。
      

  12.   

    呵呵,终于说到需求了!
    不过好像还是没有说到最后。select a.员工号,b.划卡日期,b.划卡时间
    into #Temp
    from 员工表 a,划卡记录表 b
    where a.卡号=b.卡号
    and b.划卡日期=@指定日期
    group by a.员工号,b.划卡日期update x
     set 实际=(select count(*) from #Temp where 员工号=x.员工号)
     from 另一个表 x
     where 日期=@指定日期update x
     set 实到时间1=(select top 1 划卡时间 from #Temp where 员工号=x.员工号 oeder by 划卡时间)
     from 另一个表 x
     where 日期=@指定日期delete x from #Temp x where 划卡时间=(select top 1 划卡时间 from #Temp where 员工号=x.员工号 oeder by 划卡时间)update x
     set 实到时间2=(select top 1 划卡时间 from #Temp where 员工号=x.员工号 oeder by 划卡时间)
     from 另一个表 x
     where 日期=@指定日期delete x from #Temp x where 划卡时间=(select top 1 划卡时间 from #Temp where 员工号=x.员工号 oeder by 划卡时间)
      

  13.   

    应到时间1,2 从表  班次设置来:
    (班次号 应到时间1,应到时间2,)
      1      8:00      14:00
      2      17:00      null对班次1 应刷为 2
    对班次2 应刷为 1(因为应到时间2为空)