① sql 考勤數據 未打卡的日期問題
第一個是sqlserver的,第二個是oracle的,我這里建的t5是因為沒有完整的表記錄,取不到完整的時間,而你這里的表有完整的記錄,所以select distinct substring(start_time,0,11) dt,plan_id,cardno from t5這句完全可以select distinct substring(start_time,0,11) dt,plan_id,cardno from tabname(tabname就是你上面那張表)來替代t5,這樣可以取出完整的時間集合,總不會出現所有人上班時間都沒來吧,呵呵。
createtablet5
(start_timevarchar(20),plan_idvarchar(1),cardNovarchar(10));
createtablet4
(
attend_idvarchar(4),plan_idvarchar(1),cardNovarchar(10),start_timevarchar(20),end_timevarchar(20)
);
insertintot4
select'4613','5','00009','2012-09-1108:37',null
unionall
select'4614','5','00009','2012-09-1308:53','2012-09-1318:01'
unionall
select'4615','5','00009','2012-09-1508:54','2012-09-1518:02'
unionall
select'4616','5','00009','2012-09-1708:30','2012-09-1718:03'
unionall
select'4617','5','00009','2012-09-1808:37','2012-09-1819:45'
unionall
select'4618','5','00009','2012-09-1908:37','2012-09-1919:01'
unionall
select'4619','5','00009','2012-09-2008:37','2012-09-2018:45'
unionall
select'4620','5','00009','2012-09-2108:37',null
unionall
select'4621','5','00009','2012-09-2308:37','2012-09-2318:35';
insertintot5
select'2012-09-1108:37','5','00009'
unionall
select'2012-09-1208:37','5','00009'
unionall
select'2012-09-1308:37','5','00009'
unionall
select'2012-09-1408:37','5','00009'
unionall
select'2012-09-1508:37','5','00009'
unionall
select'2012-09-1508:37','5','00009'
unionall
select'2012-09-1608:37','5','00009'
unionall
select'2012-09-1708:37','5','00009'
unionall
select'2012-09-1808:37','5','00009'
unionall
select'2012-09-1808:37','5','00009'
unionall
select'2012-09-2008:37','5','00009'
unionall
select'2012-09-2108:37','5','00009'
unionall
select'2012-09-2208:37','5','00009'
unionall
select'2012-09-2308:37','5','00009'
unionall
select'2012-09-2408:37','5','00009';
--sqlserver語句
selectt4.attend_id,
t1.plan_id,
t1.cardno,
casewhensubstring(t4.start_time,0,11)=t1.dtthent4.start_timeelset1.dt+'00:00'endstart_time,
casewhensubstring(t4.end_time,0,11)=t1.dtthent4.end_timeelset1.dt+'00:00'endend_time
from
(selectdistinctsubstring(start_time,0,11)dt,plan_id,cardnofromt5)t1
leftjoint4ont1.dt=substring(t4.start_time,0,11)andt1.cardno=t4.cardno
orderbyt1.dt;
--oracle
selectt4.attend_id,
t1.plan_id,
t1.cardno,
casewhensubstr(t4.start_time,0,10)=t1.dtthent4.start_timeelset1.dt||'00:00'endstart_time,
casewhensubstr(t4.end_time,0,10)=t1.dtthent4.end_timeelset1.dt||'00:00'endend_time
from
(selectdistinctsubstr(start_time,0,10)dt,plan_id,cardnofromt5)t1
leftjoint4ont1.dt=substr(t4.start_time,0,10)andt1.cardno=t4.cardno
orderbyt1.dt;
結果:
4613 5 00009 2012-09-1108:37 2012-09-1100:00
NULL 5 00009 2012-09-1200:00 2012-09-1200:00
4614 5 00009 2012-09-1308:53 2012-09-1318:01
NULL 5 00009 2012-09-1400:00 2012-09-1400:00
4615 5 00009 2012-09-1508:54 2012-09-1518:02
NULL 5 00009 2012-09-1600:00 2012-09-1600:00
4616 5 00009 2012-09-1708:30 2012-09-1718:03
4617 5 00009 2012-09-1808:37 2012-09-1819:45
4619 5 00009 2012-09-2008:37 2012-09-2018:45
4620 5 00009 2012-09-2108:37 2012-09-2100:00
NULL 5 00009 2012-09-2200:00 2012-09-2200:00
4621 5 00009 2012-09-2308:37 2012-09-2318:35
NULL 5 00009 2012-09-2400:00 2012-09-2400:00
有問題再追問吧,望採納。
② 用SQLserver獲取考勤打卡缺失的記錄
select * from 打卡記錄 where 最早打卡時間 is null or 最晚打卡時間 is null
③ 如何實現SQLServer與舒特考勤系統相連接
沒用過這個考勤系統
④ sqlserver考勤月度匯總sql怎麼寫
你這個表,明顯是新系統。而且沒有考勤開發經驗的。
考勤類型只分ONty和OFFty,但實際上需求4總打卡次數。。。。
而且要寫到跟你圖二一樣,還差一張排班表。。。。。
建議你這樣,先用工號、日期、ID順序歸檔一次,根據班次區間先分布沒次打卡樹葉上午還是下午,否則現在的邏輯,忘打卡一次就會導致考勤數據異常的。
⑤ 將sqlserver一張實時考勤表變成帶按月統計的(例如10月 有31天就是31個欄位 ) 根據時間分為上下午
這個根本用不著存儲過程。。發QQ給我吧。
⑥ sqlserver 查詢記錄根據人員考勤記錄去重,當時只去重當天的,不同日期的可以重復,sql怎麼寫 求助
用分析函數row_number() over (partition by ... order by ...)給記錄進行分組編號,按人員id和考勤日期進行分組(如果考勤日期帶時分秒,需先截斷到日),按時間升序排序;這樣,就得到人員ID在同一考勤日期下的編號值(編號值是從1開始的),然後,只取編號值為1的記錄。
SQL類似:
selects.id,s.name,s.date,s.card_time
from(
selectd.id,d.name,d.date,d.card_time,
row_number()over(partitionbyd.id,d.dateorderbyd.card_time)asrow_idx
fromdata_tabled
)s
wheres.row_idx=1
⑦ 求助資料庫大神,公司的考勤系統出問題,SQLserver裡面的資料庫成了灰色,連接不上,庫里也成了空的。
sql server 2008 資料庫附加後變成只讀的灰色, 解決辦法: 點擊資料庫選屬性----在選項中----狀態,在數據為只讀處選FALSE點確定即可 在之後如果報錯,空間與內存不足等情況下,找到相應的數據文件與日誌文件選擇安全添加network services 添加進去並點修改許可權。
⑧ 用 sqlserver 怎樣查詢出 數據表裡 某月上班連續打卡15天的人
這個功能資料庫用SQL語句是實現不了的,建議把每個月的上班情況讀出來,用編程語言通過編程判斷。你的需求是屬於業務邏輯功能,資料庫實現不了這么復雜的功能。
⑨ 考勤機如何連接sqlsever2000資料庫
目前市場上很多考勤機配套考勤軟體都是用ACCESS資料庫,專業版的考勤系統軟體一般都是用SQL資料庫,連接sqlserver2000資料庫其實也很簡單,以下以全易通考勤軟體連接sqlserver2000資料庫作為實例進行說明。
1、先安裝好sqlserver2000資料庫,安裝好後,啟動一下SQL伺服器
2、再安裝好考勤軟體,找到考勤軟體"創建或連接資料庫「菜單,再點創建資料庫,這時考勤軟體就會提示:操作成功!
3、如果考勤軟體提示:SQL2000不存在或拒絕訪問,這說明SQL200資料庫沒有安裝好,或SQL伺服器沒有啟動。
⑩ sql 行轉列,如圖所示是每個人每天的考勤打卡數據,怎樣可以把每個人的刷卡時間橫著顯示
如果是sqlserver你需要先建立一個函數像這樣
CREATEFUNCTION[dbo].[JoinString]
(
@timevarchar(100),
@namevarchar(100)
)
RETURNSvarchar(2000)
AS
BEGIN
DECLARE@tmpvarchar(1000)
set@tmp=''
SELECT@tmp=@tmp+','+sjfrom(
select人員姓名,CONVERT(varchar(100),刷卡日期時間,23)asrq,
CONVERT(varchar(100),刷卡日期時間,24)assj
from你的表名
)t
where人員姓名=@nameandrq=@time
RETURN@tmp
END
然後就可以調用了,如下
select人員姓名,rq,dbo.JoinString(rq,人員姓名)from
(
select人員姓名,CONVERT(varchar(100),刷卡日期時間,23)asrq,
CONVERT(varchar(100),刷卡日期時間,24)assj
from你的表名
)tgroupby人員姓名,rq