Access から SQL Server へのデータの移行。SQL Server テーブルは、inst_id、cons_code、および eff_date_time 列を主キーとして定義します。アクセスからの eff_date_time データは一意ではないため、秒フィールドを 1 秒ずつインクリメントして、一意の日時を取得しようとしました。DATEADD で日付を 1 秒増やすことができません。添付は私のコードです。私は何を間違っていますか???
USE [CON-INST]
GO
DECLARE
@cv_InstId VARCHAR(25),
@cv_ConsCode VARCHAR(10),
@cv_EffDateTime DATETIME,
@lv_count INT
DECLARE BumpDate_Cursor CURSOR
STATIC
FOR
SELECT inst_id, cons_code, eff_date_time
FROM [CON-INST].[dba].[constants_temp]
ORDER BY inst_id
OPEN BumpDate_Cursor
FETCH FIRST FROM BumpDate_Cursor
INTO @cv_InstId, @cv_ConsCode, @cv_EffDateTime
SET @lv_count = 1
// Debug statements
PRINT '@cv_InstId = ' + @cv_InstId
PRINT '@cv_ConsCode = ' + @cv_ConsCode
PRINT '@cv_EffDateTime = ' + CONVERT(VARCHAR, @cv_EffDateTime)
PRINT '@lv_count = ' + CONVERT(VARCHAR, @lv_count)
-- Loop to iterate thru instruments identifying the various constant
types that are needed, i.e. the column names - constant 1, constant 2,
constant 3, station, offset, etc.
WHILE @@FETCH_STATUS = 0
-- do processing
BEGIN
PRINT '@lv_count before = ' + CONVERT(VARCHAR, @lv_count)
PRINT CONVERT(VARCHAR, @cv_EffDateTime, 121)
IF (CONVERT(VARCHAR, @cv_EffDateTime,121) = '1901-01-01 17:00:00.000')
BEGIN
UPDATE [CON-INST].[dba].[constants_temp]
SET eff_date_time = DATEADD(second, @lv_count, eff_date_time)
WHERE inst_id = @cv_InstId and cons_code = @cv_ConsCode;
PRINT CONVERT(VARCHAR, @cv_EffDateTime, 121)
END
FETCH NEXT FROM BumpDate_Cursor
INTO @cv_InstId, @cv_ConsCode, @cv_EffDateTime
SET @lv_count = @lv_count + 1
PRINT '@lv_count after = ' + CONVERT(VARCHAR, @lv_count)
END
CLOSE BumpDate_Cursor
DEALLOCATE BumpDate_Cursor
更新前のテーブルのデータ
inst_id cons_code eff_date_time 定数 entry_user 入力コード entry_date update_user update_date
1 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:07:33.770 NULL NULL
1 PU 1901-01-01 17 :00:00.000 821.6 dba 2012-08-02 11:07:33.770 NULL NULL
1 PU 1901-01-01 17:00:00.000 8 dba 2012-08-02 11:07:33.770 NULL NULL
1 PU 1901-01- 01 17:00:00.000 2251 dba 2012-08-02 11:07:33.770 NULL NULL
2 PU 1901-01-01 17:00:00.000 2251 dba 2012-08-02 11:07:33.770 NULL NULL
2 PU 1901 01-01 17:00:00.000 22 デシベル 2012-08-02 11:07:33.770 NULL NULL
2 PU 1901-01-01 17:00:00.000 820.9 dba 2012-08-02 11:07:33.773 NULL NULL
2 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:07:33.773 NULL NULL
3 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:07:33.773 NULL NULL
3 PU 1901-01-01 17:00:00.000 821.5 dba 2012-08-02 11:07 :33.773 NULL NULL
3 PU 1901-01-01 17:00:00.000 8 デシベル 2012-08-02 11:07:33.773 NULL NULL
3 PU 1901-01-01 17:00:00.000 2095 デシベル 2012-08-02 11 :07:33.773 NULL NULL
4 PU 1901-01-01 17:00:00.000 2095 dba 2012-08-02 11:07:33.777 NULL NULL
4 PU 1901-01-01 17:00:00.000 22 dba 2012-08- 02 11:07:33.777 ヌル ヌル
4 PU 1901-01-01 17:00:00.000 820.5 dba 2012-08-02 11:07:33.777 NULL NULL
4 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:07:33.777 NULL NULL
A PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:07:33.777 NULL NULL
A PU 1901-01-01 17:00:00.000 816.8 dba 2012-08-02 11:07 :33.777 NULL NULL
A PU 1901-01-01 17:00:00.000 120.5 dba 2012-08-02 11:07:33.780 NULL NULL
A PU 1901-01-01 17:00:00.000 2255 dba 2012-08-02 11 :07:33.780 NULL NULL
A-1 AS 1972-07-01 00:00:00.000 1492 dba 2012-08-02 11:07:33.780 NULL NULL
A-1 AS 1972-07-01 00:00:00.000 986.48 dba 2012-08-02 11:07:33.780 ヌル ヌル
A-1 AS 1972-07-01 00:00:00.000 0 デシベル 2012-08-02 11:07:33.780
ヌルヌル:07:33.780 NULL NULL
A-10 AS 1972-07-01 00:00:00.000 986.48 dba 2012-08-02 11:07:33.780 NULL NULL
A-10 AS 1972-07-01 00:00:00.000 1857 dba 2012-08-02 11:07:33.780 NULL NULL
A-11 AS 1972-07-01 00:00:00.000 1896 dba 2012-08-02 11:07:33.783 NULL NULL
A-11 AS 1972-07-01 00 :00:00.000 986.5 dba 2012-08-02 11:07:33.783 NULL NULL
A-11 AS 1972-07-01 00:00:00.000 0 dba 2012-08-02 11:07:33.783 NULL NULL
A-12 AS 1972-07-01 00:00:00.000 0 デシベル 2012-08-02 11:07:33.783 NULL NULL
A-12 AS 1972-07-01 00:00:00.000 986.5 dba 2012-08-02 11:07:33.783 NULL NULL
A-12 AS 1972-07-01 00:00:00.000 1936 dba 2012-08-02 11 :07:33.783 ヌルヌル
実行中の PRINT ステートメントからの出力
@cv_InstId = 1
@cv_ConsCode = PU
@cv_EffDateTime = 1901 年 1 月 1 日午後 5 時
@lv_count = 1
更新前: 1901-01-01 17:00:00.000
@lv_count = 2
更新前: 1901-01-01 17:00:00.000
@lv_count = 3
更新前: 1901-01-01 17:00:00.000
@lv_count = 4
更新前: 1901-01-01 17:00:00.000
@lv_count = 5
更新前: 1901-01-01 17:00:00.000
@lv_count = 6
更新前: 1901-01-01 17:00:00.000
@lv_count = 7
更新前: 1901-01-01 17:00:00.000
@lv_count = 8
更新前: 1901-01-01 17:00:00.000
@lv_count = 9
更新前: 1901-01-01 17:00:00.000
@lv_count = 10
更新前: 1901-01-01 17:00:00.000
@lv_count = 11
更新前: 1901-01-01 17:00:00.000
@lv_count = 12
更新前: 1901-01-01 17:00:00.000
@lv_count = 13
更新前: 1901-01-01 17:00:00.000
@lv_count = 14
更新前: 1901-01-01 17:00:00.000
@lv_count = 15
更新前: 1901-01-01 17:00:00.000
@lv_count = 16
更新前: 1901-01-01 17:00:00.000
@lv_count = 17
更新前: 1901-01-01 17:00:00.000
@lv_count = 18
更新前: 1901-01-01 17:00:00.000
@lv_count = 19
更新前: 1901-01-01 17:00:00.000
@lv_count = 20
更新前: 1901-01-01 17:00:00.000
@lv_count = 21
更新前: 1972-07-01 00:00:00.000
@lv_count = 22
更新前: 1972-07-01 00:00:00.000
@lv_count = 23
更新前: 1972-07-01 00:00:00.000
@lv_count = 24
更新前: 1972-07-01 00:00:00.000
@lv_count = 25
更新前: 1972-07-01 00:00:00.000
表 実行後の出力
inst_id cons_code eff_date_time 定数 entry_user entry_date update_user update_date
1 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:28:27.287 NULL NULL
1 PU 1901-01-01 17:00:00.000 821.6 dba 2012-08-02 11:28:27.287 NULL NULL
1 PU 1901-01-01 17:00:00.000 8 dba 2012-08-02 11:28:27.290 NULL NULL
1 PU 1901-01-01 17:00 :00.000 2251 dba 2012-08-02 11:28:27.290 NULL NULL
2 PU 1901-01-01 17:00:00.000 2251 dba 2012-08-02 11:28:27.290 NULL NULL
2 PU 1901-07-01 1 :00:00.000 22 デシベル 2012-08-02 11:28:27.290 NULL NULL
2 PU 1901-01-01 17:00:00.000 820.9 dba 2012-08-02 11:28:27.290 NULL NULL
2 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:28:27.290 NULL NULL
3 PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:28:27.290 NULL NULL
3 PU 1901-01-01 17:00:00.000 821.5 dba 2012-08-02 11:28 :27.290 NULL NULL
3 PU 1901-01-01 17:00:00.000 8 デシベル 2012-08-02 11:28:27.290 NULL NULL
3 PU 1901-01-01 17:00:00.000 2095 デシベル 2012-08-02 11 :28:27.293 NULL NULL
4 PU 1901-01-01 17:00:00.000 2095 dba 2012-08-02 11:28:27.293 NULL NULL
4 PU 1901-01-01 17:00:00.000 22 dba 2012-08- 02 11:28:27.293 ヌル ヌル
4 PU 1901-01-01 17:00:00.000 820.5 DBA 2012-08-02 11:28:27.293 NULL NULL
4 PU 1901-01-01 17:00:00.000 833.2 DBA 2012-08-02 11:28:27.293 NULL NULL
A PU 1901-01-01 17:00:00.000 833.2 dba 2012-08-02 11:28:27.293 NULL NULL
A PU 1901-01-01 17:00:00.000 816.8 dba 2012-08-02 11:28 :27.293 NULL NULL
A PU 1901-01-01 17:00:00.000 120.5 dba 2012-08-02 11:28:27.297 NULL NULL
A PU 1901-01-01 17:00:00.000 2255 dba 2012-08-02 11 :28:27.297 NULL NULL
A-1 AS 1972-07-01 00:00:00.000 1492 dba 2012-08-02 11:28:27.297 NULL NULL
A-1 AS 1972-07-01 00:00:00.000 986.48 dba 2012-08-02 11:28:27.297 NULL NULL
A-1 AS 1972-07-01 00:00:00.000 0 デシベル 2012-08-02 11:28:27.297
ヌルヌル:28:27.297 NULL NULL
A-10 AS 1972-07-01 00:00:00.000 986.48 dba 2012-08-02 11:28:27.300 NULL NULL
A-10 AS 1972-07-01 00:00:00.000 1857 dba 2012-08-02 11:28:27.300 NULL NULL
A-11 AS 1972-07-01 00:00:00.000 1896 dba 2012-08-02 11:28:27.300 NULL NULL
A-11 AS 1972-07-01 00 :00:00.000 986.5 dba 2012-08-02 11:28:27.300 NULL NULL
A-11 AS 1972-07-01 00:00:00.000 0 dba 2012-08-02 11:28:27.300 NULL NULL
A-12 AS 1972-07-01 00:00:00.000 0 デシベル 2012-08-02 11:28:27.300 NULL NULL
A-12 AS 1972-07-01 00:00:00.000 986.5 dba 2012-08-02 11:28:27.300 NULL NULL
A-12 AS 1972-07-01 00:00:00.000 1936 dba 2012-08-02 11 :28:27.300 NULL NULL
A-13 AS 1972-07-01 00:00:00.000 1976 dba 2012-08-02 11:28:27.300 NULL NULL
A-13 AS 1972-07-01 00:00:00.000 986.46 dba 2012-08-02 11:28:27.300 NULL NULL
A-13 AS 1972-07-01 00:00:00.000 0 dba 2012-08-02 11:28:27.303 NULL NULL
A-14 AS 1972-07-01 00 :00:00.000 0 dba 2012-08-02 11:28:27.303 NULL NULL
A-14 AS 1972-07-01 00:00:00.000 986.48 dba 2012-08-02 11:28:27.303 NULL NULL
A-14 AS 1972-07-01 00:00:00.000 2016 dba 2012-08-02 11:28:27.303 NULL NULL
A-15 AS 1972-07-01 00:00:00.000 0 dba 2012-08-02 11:28:27.303 NULL NULL