【发布时间】:2023-01-04 20:34:42
【问题描述】:
我是新来的,但这是我获得 SQL 帮助的唯一想法。我是 SQL 查询的新手,只知道它的基础知识,所以我希望你能理解我。 我做了 2 个查询 - #1 查询创建了包含很多行的表 tempBus。并插入来自 Stock Procedure 的数据。 然后我得到带有数据的表 tempBus。现在 #2 查询正在创建另一个表 tempBus2,它仅从表 tempBus 中插入特定数据,并将一些字段从 1 转换为 YES,从 0 转换为 NO。但是在运行我的 #2 查询时我得到了不正确的语法错误。 例子:
use DATABASE
IF OBJECT_ID('tmpBus2') IS NOT NULL
DROP TABLE tmpBus2
CREATE TABLE tmpBus2
(
Application nvarchar(50),
OrgHierarchy nvarchar(max),
ManufacturerName nvarchar(50),
ApplicationMetric nvarchar(100),
TotalLicenses int,
LicenseRequirement int,
AvailableLicenses int,
Compliance int
)
insert into dbo.tmpBus2
Application,
OrgHierarchy AS 'Organisation',
manufacturername AS 'Manufacturer',
(case applicationmetric
when '1' then 'Installations'
when '2' then 'Custom compare values'
when '7' then 'Number of processors'
when '8' then 'Number of processor cores'
when '9' then 'Users'
when '10' then 'Devices'
when '11' then 'Concurrent users'
when '12' then 'Concurrent devices'
when '13' then 'PVU'
when '14' then 'CAL (Client Access License)'
else 'Unknown'
end) AS 'Metric',
totallicenses AS 'Total Licenses',
Licenserequirement AS 'License Requirement',
availablelicenses AS 'Available Licenses',
Compliance AS 'Compliance'
from tmpbus
它给我错误:消息 102,级别 15,状态 1,第 21 行。“应用程序”附近的语法不正确。
我希望将数据放入 tmpBus2 表中,并将 ApplicationMetric 显示为文本,而不是 1-14 的数字。
【问题讨论】:
-
缺少选择。
-
请注意,表格有列,不是字段。
-
你好@jarlh!这个 SELECT 应该在 INSERT 之前?
-
INSERT INTO targettable SELECT ...
标签: sql