更新时间:2023-01-22 09:06:26
1) union all 4,'office4'
,如错误所示,是错误的语法。你需要
1) union all 4,'office4'
is, as the error says, the incorrect syntax. You need to
SELECT 4,'office4'
2)我猜你设置 facility_id
带有IDENTITY(1,1)子句 - 这将由DBMS自动生成。仍然可以在插入上定义这些 - 在MSDN中查找 IDENTITY INSERT ON
3)您之前尝试过的数据库中已经有#facility2 - 在这种情况下,您应首先 DROP
表 - 或者查询的第一部分是创建表和第二部分部分正在生成错误。尝试
2) I presume that you set up facility_id
with the IDENTITY(1,1) clause - this will be generated automatically by the DBMS. It is still possible to define these on an insert - look up IDENTITY INSERT ON
in MSDN
3) Either you already have #facility2 on your database from your previous attempts - in which case you should DROP
the table first - or the first part of your query is creating the table and the 2nd part is generating the error. Try
select facility_id,Facility_Name into #facility2 from tbl_facility where hub=1
insert into #facility2 select facility_id,Facility_Name from tbl_facility where facility_id=236
(当您将记录插入表格时,不需要联合)
4)见上文(2)。
5)这是正确的方法 - 通过明确声明 facility_id int,
(即没有您可以直接插入数据的IDENTITY子句
(There is no need for the union as you're inserting the records into a table)
4) See (2) above.
5) This is the correct way to go about this - by explicitly declaring facility_id int,
(i.e. without the IDENTITY clause) you can insert the data directly