【发布时间】:2016-03-20 05:50:10
【问题描述】:
尝试使用 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 ....。 -
Bad habits to kick : using old-style JOINs - 旧式 逗号分隔的表格列表 样式已替换为 ANSI 中的 proper ANSI
JOIN语法-92 SQL 标准(20 多年前),不鼓励使用它
标签: sql sql-server sql-server-2008 tsql