2016-07-05 94 views
2

我遇到了這個錯誤與我的發言:SQL Server錯誤:char數據類型轉換爲smalldatetime數據類型導致超出範圍的SMALLDATETIME值

insert into messages ([from], [to], [message], Subject, status, senderID, 
         PassengerID, Taxis, bags, passengers, dest, Comments, [when]) 
values(2, 81, '2', 'Bid', 1, 2, 
     2, 2, 2, 2, '2', '2', CONVERT(smalldatetime, '25.7.2016 13:01')) 

我得到這個錯誤:

The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.

在控制檯上運行相同的語句時,它工作得很好!

+0

「當在控制檯上運行相同的語句時,它完美無缺!那麼它不工作?從一個Web應用程序?從遠程SSMS? –

回答

1

您需要Convert功能來指定一個合適的style參數是這樣 -

Insert into messages ([from],[to],[message],Subject,status,senderID,PassengerID,Taxis,bags,passengers, dest, Comments,[when]) 
    values(2,81,'2','Bid',1,2,2,2,2,2,'2','2',CONVERT(smalldatetime, '25.7.2016 13:01', 104)) 
+0

謝謝,它的工作原理。但是爲什麼在控制檯中它是完美的? – Meir

+0

控制檯上的區域設置與[未指定的其他地方無法使用]必須不同,並且日期內的日/月不同。 –

+0

@underscore_d:是的,我同意你的看法。 –

1

這與你的服務器設置做。似乎您的服務器在輸入歐洲格式(dd mm yyyy)時等待美國日期格式(mm dd yyy)。

相關問題