从Excel运行SQL Server存储过程问题
问题描述:
我正在尝试创建一个Excel电子表格,该电子表格将运行一些SQL代码,这是我在过去为简单的选择语句所做的,但现在还有一些更高级的代码,我不断收到错误当我尝试从Excel运行SQL Server存储过程时,即使它在SQL Server Management Studio中运行良好。从Excel运行SQL Server存储过程问题
存储过程的代码是:
truncate table LAS_RPT_IST;
insert into LAS_RPT_IST (IST_Ref_no, IST_Inv_no, LDC_ACCT_ID, IST_Commodity, IST_Tax, IST_STRS, START_DT, END_DT)
(Select
th.user1_tx, th.user4_tx, ldc.ldc_acct_id,
sum(case when th.trans_sub_ty_cd = 'ISTC' then th.trans_am end) as ISTC,
sum(case when th.trans_sub_ty_cd = 'TAX' then th.trans_am end) as TAX,
sum(case when th.trans_sub_ty_cd = 'STRS' then th.trans_am end) as STRS,
th.generic1_dt, th.generic2_dt
from
transaction_history th, ldc_Account ldc
where
th.trans_creation_dt > = Convert(varchar(8),DateAdd(d, -1, Convert(datetime, N'20140930', 101)), 112)
and th.user10_tx = 'IST'
and th.ldc_acct_id = ldc.ldc_acct_id
group by
th.user1_tx, th.user4_tx, ldc.ldc_acct_id, th.generic1_dt, th.generic2_dt);
但是,当我把这个成Excel和尝试,并运行它,我得到这个错误
我可以运行对SELECT语句来自Excel的数据库没有问题。
谁能告诉我我失踪了什么?
答
您必须在单独的命令中运行TRUNCATE和INSERT操作。
你为什么要把这段代码放到你的Excel电子表格中?把它变成一个存储过程并从Excel中执行它。 – 2014-09-30 15:45:16
向我们提供有关如何运行这些查询的更多信息。我首先想到的是,在Excel ADO中一次不能运行超过1个查询 - 您必须单独运行它们。 – 2014-09-30 15:51:25
我其实正试图让一个商店程序运行上面的代码就是SP中的内容。 – 2014-09-30 16:12:04