0
使用VB 6和Access數據庫如何訂購表格?
我的查詢。
創建一個表
sql4 = "CREATE TABLE tmp_MOI (RECORDNO varchar(20), PERSONID varchar(20), EmpName varchar(50), TitleName varchar(50), Titlecode varchar(50), Department varchar(50), Nation varchar(50), CardEventDate varchar(50), Intime varchar(20), Outtime varchar(20), PrevDate varchar(50), PrevOut varchar(20))"
If rstmpCardEvent1.State = 1 Then rstmpCardEvent1.Close
rstmpCardEvent1.Open sql4, Cn, adOpenStatic, adLockOptimistic
從表中選擇一個字段,並保存到記錄
sql9 = "SELECT RECORDNO, PERSONID, EMPNAME, TITLENAME, TITLECODE, DEPARTMENT, NATION, CARDEVENTDATE, INTIME, OUTTIME, (select TOP 1 F1.CARDEVENTDATE from tmp_cardevent as F1 where F1.RECORDNO < F2.RECORDNO AND F1.PERSONID = F2.PERSONID order by F1.RECORDNO DESC, F1.PERSONID DESC) AS PrevDate, (select TOP 1 F1.OUTTIME from tmp_cardevent as F1 where F1.RECORDNO < F2.RECORDNO AND F1.PERSONID = F2.PERSONID order by F1.RECORDNO DESC, F1.PERSONID DESC) AS PrevOut FROM tmp_cardevent AS F2 ORDER BY F2.NATION, F2.TITLECODE, F2.PERSONID, F2.CARDEVENTDATE"
If rsCardEvent1.State = 1 Then rsCardEvent1.Close
rsCardEvent1.Open sql9, Cn, adOpenStatic, adLockOptimistic
cmdcardevent1.CommandText = sql9
Set rsCardEvent1 = cmdcardevent1.Execute
插入域到表
While Not rsCardEvent1.EOF
sql10 = "INSERT INTO tmp_MOI values('" & rsCardEvent1(0).Value & "' , '" & rsCardEvent1(1).Value & "', '" & rsCardEvent1(2).Value & "', '" & rsCardEvent1(3).Value & "', '" & rsCardEvent1(4).Value & "', '" & rsCardEvent1(5).Value & "', '" & rsCardEvent1(6).Value & "', '" & StringToDate(rsCardEvent1.Fields(7).Value) & "', '" & rsCardEvent1.Fields(8).Value & "', '" & rsCardEvent1.Fields(9).Value & "', '" & StringToDate(rsCardEvent1.Fields(10).Value) & "', '" & StringToTim(rsCardEvent1(11).Value) & "') ORDER BY '" & rsCardEvent1(4).Value & "'"
If rstmpCardEvent1.State = 1 Then rstmpCardEvent1.Close
rstmpCardEvent1.Open sql10, Cn, adOpenStatic, adLockOptimistic
rsCardEvent1.MoveNext
Wend
當我檢查這個查詢在訪問數據庫中 - 它顯示正確,按國家排序,類似於001,002,003秒o在...,PERSONID,cardeventdate
國家,PERSONID,cardeventdate正確地顯示在tmp_MOI表
,但我不會在tmp_MOI表正確獲得冠軍的代碼,它顯示像001在tmp_MOI表titlecode, 002,001,003,002等...
我的代碼有什麼問題,是我的代碼中的任何問題?
需要查詢或代碼幫助
如何使用ORDER BY'「&rsCardEvent1(4).Value&」'「,當我插入值的順序時,它顯示錯誤 – Gopal 2009-07-16 04:58:37