Created
December 19, 2012 14:00
-
-
Save masakiplus/4336856 to your computer and use it in GitHub Desktop.
stored procedure to import csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 取り込み用ローデータの削除 | |
DELETE [r_tbl]; | |
-- データの取り込み実施 | |
BULK INSERT [r_tbl] from 'raw.txt' WITH | |
( | |
FIELDTERMINATOR = '\t', | |
ROWTERMINATOR = '0x0a' | |
); | |
-- 必要なカラムだけ型変換してインサート | |
MERGE | |
INTO [tbl] as T | |
USING [r_tbl] as R | |
ON T.[user_id] = R.[user_id] | |
WHEN MATCHED THEN | |
UPDATE | |
SET T.[date] = R.[date] | |
WHEN NOT MATCHED THEN | |
INSERT ([user_id],[date]) | |
VALUES (R.[user_id],R.[date); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment