我创建了 ssis 包以从 sql 表动态生成 excel 文件。
但是,当我尝试在 sql 任务中使用以下查询检查该 excel 连接临时表是否存在时,它会出现语法错误
IF object_id(MyExcel) is not null
CREATE TABLE `MyExcel` (
`CUSIP` varchar(50),
`FaceAmount` decimal(18,4),
`Portfolio` varchar(50),
`PositionDate` DateTime,
`PositionCost` decimal(18,6),
`CurrentPrice` decimal(18,6)
)
else drop table MyExcel
错误 :
[Execute SQL Task] Error: Executing the query "IF object_id(MyExcel) is not null
CREATE TABLE `..." failed with the following error: "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
请指教?
我试过回答
IF OBJECT_ID(N'MyExcel') IS NOT NULL
BEGIN
DROP TABLE MyExcel;
END;
CREATE TABLE [MyExcel]
(
[CUSIP] VARCHAR(50),
[FaceAmount] DECIMAL(18,4),
[Portfolio] VARCHAR(50),
[PositionDate] DATETIME,
[PositionCost] DECIMAL(18,6),
[CurrentPrice] DECIMAL(18,6)
);
但是对于语句仍然出现相同的错误
IF OBJECT_ID(N'MyExcel') IS NOT NULL
BEGIN
DROP TABLE MyExcel;
END;
我在SQL TASK
Connection 类型中使用这个查询是EXCEL