嘗試使用SQL Server 2008中插入值到一個臨時表,得到:問題插入值與子查詢到臨時表中的SQL Server 2008
消息116,級別16,狀態1,過程Test_temp_table,274線
當子查詢未與EXISTS一起引入時,只能在選擇列表中指定一個表達式。
與此查詢:
VALUES(
(select
a.*, b.[formal name], c.*, d.*
from
selecthr20.employee.[career history] a,
selecthr20.Employee.[Current Appointments As At Evaluation Date] b,
Employee.[BSK Changes in Selected Period] c,
selecthr20.employee.[career history extra detail] d
where
a.[appointment number] = b.[appointment number]
and a.[career number] = c.[primary key number]
and a.[career number] = d.[career number]
and c.[primary key number] = d.[career number]
and c.[primary key name] = 'Career Number'
and b.[person number] in (select b.[person number]
from employee.[current pay as at evaluation date]
where substring([Payroll Name],1,6) = 'DOV020')))
您似乎使用錯誤的語法。 'INSERT INTO ... SELECT'根本不使用'VALUES()'表達式。它只是'INSERT INTO #TempTable SELECT ....'。 –
[踢壞的習慣:使用舊式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins。 aspx) - 在ANSI - ** 92 ** SQL標準(**超過20年前的**)中,舊式*逗號分隔的表*樣式列表被替換爲* proper * ANSI'JOIN'語法它的使用是不鼓勵的 –