我試圖執行語句以將變量附加到表名稱。我是新來的SQL和我找不到在線問題的解決方案。當在sql server中使用時間變量時,必須聲明標量變量
Declare @t time
Set @t='12:00:00.1'
Declare @ttable varchar (255)
Set @ttable='Temp'+(Select top 1 ID from mtable)
Exec('Insert into '[email protected]+'(Timestamp) values ('+'@t'+')')
每當我運行此查詢我得到以下錯誤:
Msg 137, Level 15, State 2, Line 1 Must declare the scalar variable "@t".
我不知道到底是什麼,我上運行。我剛剛打開SQL Server Management Studio(SQL Server 2008 R2)並創建了一個數據庫和表。任何幫助深表感謝。
串門@t報價在EXEC? –
編輯您的問題並提供樣本數據,所需結果並解釋您正在嘗試執行的操作。 「將變量附加到表名」是不明智的。 –