sql-server - 联合查询结果到临时表
问题描述
我有一个要插入临时表的子查询。但是,我收到语法错误,例如SQL Error [102] [S0001]: Incorrect syntax near ')'.
.
select *
into #TempTable
from (
SELECT x,y,z
FROM
schemaA.tableC
where (x = '1234')
UNION
SELECT x,y,z
FROM
schemaB.tableC
where (x = '1234')
)
select *
from #TempTable
解决方案
您需要为内部查询提供别名:
select *
into #TempTable
from (
SELECT x,y,z
FROM
schemaA.tableC
where (x = '1234')
UNION
SELECT x,y,z
FROM
schemaB.tableC
where (x = '1234')
) AS P
select *
from #TempTable
简单来说,结构是:
SELECT
*
FROM
(SELECT * FROM MyTable) AS P
推荐阅读
- python - MongoDB 使用同一个文档更新整个集合
- android - 创建餐厅/酒吧菜单应用程序的最佳解决方案
- excel - 计算年化平均回报
- ios - Xcode SpriteKit 游戏 - 如何在应用安装期间为多种屏幕尺寸配置 UI
- php - 内存泄漏 - 一个简单的 phpinfo() 页面会增加容器内存使用量
- android - 检查互联网
- javascript - React Native 条件渲染自定义卡片样式问题
- selenoid - 无法使用 docker 启动 selenoid 服务器
- javascript - Nodejs docx-merger 插件“Word 发现不可读的内容”
- react-native - 根据语言选择重新渲染当前视图