简体   繁体   English

SQL 关键字“IF”附近的语法不正确

[英]SQL Incorrect syntax near the keyword 'IF'

I have this code that I need to translate from Oracle to SQL Server and I'm getting this error message:我有此代码需要从 Oracle 转换为 SQL 服务器,我收到此错误消息:

"MMsg 156, Level 15, State 1, Line 23 Incorrect syntax near the keyword 'IF'. “MMsg 156,级别 15,State 1,第 23 行关键字 'IF' 附近的语法不正确。

This is also connecting to another SQL Server.这也连接到另一个 SQL 服务器。 It is pulling data from one SQL Server and adding it to another SQL Server.它从一台 SQL 服务器中提取数据并将其添加到另一台 SQL 服务器。

The code is below.代码如下。

--Import Parcel
DROP TABLE IF EXISTS VISION_PARCEL;
SELECT * 
INTO [dbo].[VISION_PARCEL]
FROM [TOMSQLVISION].[VISION_2020].[REAL_PROP].[PARCEL]

(Assuming that your code is on SQL Server) To check whether table exists before Select Into , use the following (假设你的代码在SQL服务器上)要检查Select Into ,使用如下

IF OBJECT_ID('dbo.VISION_PARCEL', 'U') IS NOT NULL 
Begin
    DROP TABLE dbo.VISION_PARCEL; 
End

Then Execute然后执行

SELECT * 
INTO [dbo].[VISION_PARCEL]
FROM [TOMSQLVISION].[VISION_2020].[REAL_PROP].[PARCEL]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM