我有這樣的代碼(SQL Server 2008中)錯誤,同時通過在SQL Server中的多個表的循環2008
EXEC sp_MSforeachtable
'
IF ''?'' LIKE ''%_records%''
BEGIN
Update ? set Status = ''expired'' where expire_date_time <= getdate()
END'
當我執行此查詢時,它更新了表,但它顯示如下錯誤:
Msg 207, Level 16, State 1, Line 6
Invalid column name 'expire_date_time'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'expire_date_time'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'expire_date_time'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'expire_date_time'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'expire_date_time'.
Msg 207, Level 16, State 1, Line 6
Invalid column name 'expire_date_time'.
爲什麼這樣呢?有人可以用正確的代碼指導我嗎?我想把這個代碼放在事件中,所以它會在特定的時間間隔後檢查條件。
是否每個包含名爲'_records_'的表都有'expire_date_time'列? – Lamak
我會冒險猜測這是因爲在幾個數據庫中沒有名爲「expire_date_time」的列。 –
是的。例如:username_records,如果用戶名是jason,那麼tablename是jason_records。每個表都有expire_date_time列。 –