- 資料來源
Numbers ------- 10 12 19 25 25 34 38
- 產生結果
Closest Number -------------- 25
- 規則
- SQL Server 2005 以上的版本
- 產生結果的欄位名稱,必須是Closest Number
- 一定要使用次序函數
Numbers ------- 10 12 19 25 25 34 38
Closest Number -------------- 25
YearMonth Score ----------- ----------- 200903 100 200803 95 200802 99 200801 100 200711 100
YearMonth Score ----------- ----------- 200908 100 200907 100 200906 100 200905 100 200904 100 200903 100 200902 95 200901 95 200812 95 200811 95 200810 95 200809 95 200808 95 200807 95 200806 95 200805 95 200804 95 200803 95 200802 99 200801 100 200712 100 200711 100
TRY
loExcel = CREATEOBJECT("Excel.Application")
IF VARTYPE(loExcel) = "O"
lcExcelVersion = ALLTRIM(loExcel.APPLICATION.NAME)
lnExcelVersion = VAL(loExcel.APPLICATION.VERSION)
DO CASE
CASE lnExcelVersion = 14
lcExcelVersion = lcExcelVersion + " 2010"
CASE lnExcelVersion = 12
lcExcelVersion = lcExcelVersion + " 2007"
CASE lnExcelVersion = 11
lcExcelVersion = lcExcelVersion + " 2003"
CASE lnExcelVersion = 10
lcExcelVersion = lcExcelVersion + " XP"
CASE lnExcelVersion = 09
lcExcelVersion = lcExcelVersion + " 2000"
CASE lnExcelVersion = 08
lcExcelVersion = lcExcelVersion + " 97"
OTHERWISE
lcExcelVersion = lcExcelVersion + " " + ALLTRIM(STR(lnExcelVersion))
ENDCASE
lnExcelVersion = loExcel.APPLICATION.International(1)
DO CASE
CASE lnExcelVersion = 1
lcExcelVersion = lcExcelVersion + " 英文版"
CASE lnExcelVersion = 886
lcExcelVersion = lcExcelVersion + " 繁體中文版"
CASE lnExcelVersion = 86
lcExcelVersion = lcExcelVersion + " 簡體中文版"
OTHERWISE
lcExcelVersion = lcExcelVersion + " 非英繁簡版(其國碼=" + ALLTRIM(STR(lnExcelVersion)) + ")"
ENDCASE
loExcel.QUIT
ENDIF
CATCH
-- 不產生任何錯誤訊息
lcExcelVersion = "沒有安裝 Excel 軟體"
ENDTRY
MESSAGEBOX(lcExcelVersion) -- 顯示偵測 Excel 結果
EmployeeID PayType PayHours ---------- ------- -------- 10001 R 01:30 10001 R 05:15 10001 O 01:00 10001 H 01:30 10002 R 08:00 10002 I 01:00 10002 I 01:30第一個欄位儲存員工工號。第二個欄位儲存付款類別。R 代表 一般工作時數、H 代表 假日等意義。每一個員工付款類別必須累加。產生的結果,每一個員工必須只有一個 ROW 資料。
Employee Code1 Pay1 Code2 Pay2 Code3 Pay3 Code4 Pay4 -------- ----- ---- ----- ---- ----- ---- ----- ---- 10001 R 6.75 O 1.00 H 1.50 0.00 10002 R 8.00 I 2.50 0.00 0.00