2017-05-18 17 views
1

我試圖導入以下數據:試圖SQL數據導入到Visual Studio的Web形式的數據庫

(的LocalDB)\ MSSQLLocalDB

CREATE TABLE shifts (

shift_id int NOT NULL, 
    shift_facility_id int NOT NULL, 
    shift_user_id varchar(64) NOT NULL, 
    shift_start_time datetime NOT NULL, 
    shift_replacement varchar(64) DEFAULT NULL, 
    shift_request_replacement varchar(65) DEFAULT NULL 
) 

INSERT INTO shifts (shift_id, shift_facility_id, shift_user_id, shift_start_time, shift_replacement, shift_request_replacement) VALUES 
(1, 57, '1', '2017-05-19 00:00:00.000000', NULL, NULL), 
(2, 57, '1', '2017-05-19 12:00:00.000000', NULL, NULL), 
(3, 57, '1', '2017-05-20 00:00:00.000000', NULL, NULL), 
(4, 57, '1', '2017-05-20 12:00:00.000000', NULL, NULL), 
(5, 57, '2', '2017-05-21 00:00:00.000000', NULL, NULL), 
(62, 59, '6', '2017-05-19 00:00:00.000000', NULL, NULL), 
(64, 60, '4', '2017-05-19 00:00:00.000000', NULL, NULL); 
在以下數據庫

但是我不斷收到錯誤

Conversion failed when converting date and/or time from character string. 

我試圖從查詢本身中刪除每個'(它修復了以前的問題一次),但這次沒有成功。

'2017-05-20 12:00:00.000000' 

有誰知道如何使這個SQL查詢可執行文件:

由這些部件產生的誤差?

回答

3

只是這樣做:

INSERT INTO shifts (shift_id, shift_facility_id, shift_user_id, shift_start_time, shift_replacement, shift_request_replacement) 
VALUES 
      (1, 57, '1', '2017-05-19 00:00:00', NULL, NULL), 
      (2, 57, '1', '2017-05-19 12:00:00', NULL, NULL), 
      (3, 57, '1', '2017-05-20 00:00:00', NULL, NULL), 
      (4, 57, '1', '2017-05-20 12:00:00', NULL, NULL), 
      (5, 57, '2', '2017-05-21 00:00:00', NULL, NULL), 
      (62, 59, '6', '2017-05-19 00:00:00', NULL, NULL) 
      (64, 60, '4', '2017-05-19 00:00:00', NULL, NULL); 

你有一個datetime場,你並不需要比這更精密所以到了分鐘,你應該確定。

+2

..或使shift_start_time成爲'datetime2'列。 – stuartd

+0

如果你可以改變表格結構... :) –

+0

當然,但是在這個問題上有一個'CREATE TABLE':) – stuartd

相關問題