从存储过程

时间:2016-03-17 15:53:34

标签: sql-server matlab

我正在尝试从matlab调用microsoft sql server中的存储过程。

存储过程需要一个输入并返回一行,其中包含10列,其中所有列都是数字。

我一直在努力追随matlab page,但没有快乐。我得到的错误信息是

 Error using database/runstoredprocedure (line 81)
Java exception occurred:
com.microsoft.sqlserver.jdbc.SQLServerException: Procedure or function usp_cap_wgt_factors has too many arguments specified.

Matlab代码

inputarg = {'2016-03-11'};
outputtype = {java.sql.Types.NUMERIC};
results = runstoredprocedure(QES_DB,'usp_cap_wgt_factors', inputarg, outputtype);

我如何在sql中调用我的存储过程

exec usp_cap_wgt_factors '2016-03-11'

更新

如果我尝试下面这一行,我会收到以下错误消息“来自非单元格数组对象的单元格内容引用。”

 inputarg = char(datestr('2016-03-11', 'yyyy-mm-dd'));

sql程序

CREATE PROCEDURE usp_cap_wgt_factors
@factDate as date   
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
;with totVal as
(
    select sedolchk,  mv_usd / (select sum(mv_usd) from D_FACTORS where pricedatew = @factDate) wgt
    from D_FACTORS where pricedatew = @factDate

), factors as
(
    select sedolchk, ubeta180w, ratebeta180w, yxdbeta180w, crbbeta180w, idiovol, lnr05204w, lnr18053w, mv_usd, bp from D_FACTORS 
    where pricedatew = @factDate
)
select sum(ubeta180w * wgt) ubeta180w, sum(ratebeta180w * wgt) ratebeta180w, sum(yxdbeta180w * wgt) yxdbeta180w,
sum(crbbeta180w * wgt) crbbeta180w, sum(idiovol * wgt) idiovol, sum(lnr05204w * wgt) lnr05204w,
sum(lnr18053w * wgt) lnr18053w, sum(mv_usd * wgt) mv_usd, sum(bp * wgt) bp
from factors f inner join totVal tv on f.sedolchk = tv.sedolchk

0 个答案:

没有答案