我的表名中包含以下列:Trip;回覆:在SQL Server中減去兩個其他列的計算列
trip_no (PK, int, not null),
ID_company (FK, int not null),
plane (char(25), not null),
town_from (char(25) not null),
town_to (char(25) not null),
time_out (datetime, not null),
time_in (datetime, not null),
time_out_only (time(0), null),
time_in_only (time(0) null),
time_in_flight (time(0) null);
對於最後三列我的第一行看起來像這樣;
time_out_only time_in_only time_in_flight
14:30:00 17:50:00 null
我想要飛行時間計算到02:20:00。所以,我想的代碼time_in_flight等於time_in_only少time_out_only,如下,
ALTER TABLE Trip
SET time_in_flight = time_in_only - time_out_only;
我接收的錯誤消息是
「消息102,級別15,狀態1,2.不正確的行語法靠近 'Time_in_Flight'。
除非我不正確的是使用SET,我應該使用不同的功能,我很困惑,因爲我要去哪裏錯了。但是我以前認爲這個語法對我有用。
任何人都可以指導我在哪裏我錯了,並幫助我弄清楚如何使用一些函數和公式減去兩列。
謝謝喬西
好事者好奇:您可以從23:30到1:50(又名從第一天到第二天)航班嗎?你能否有持續24小時以上的航班(旅程,旅程)? –
@PhilipKelley .......是的,我可以有超過24小時的航班,最後看討論。謝謝 – Josie