--
删除存储过程
DROP PROCEDURE Test
GO
-- 定义一个存储过程, 两个输入参数
CREATE PROCEDURE Test
@INPUT1 VARCHAR ( 255 ),
@INPUT2 VARCHAR ( 255 ),
@INPUT3 VARCHAR ( 255 )
AS
BEGIN
DECLARE @object INT -- 实例
DECLARE @err INT -- 是否成功
DECLARE @return_value VARCHAR ( 255 ) -- 返回值
DECLARE @src VARCHAR ( 255 ), @desc VARCHAR ( 255 ) -- 错误信息
/**/ /*1.创建COM实例, 调用CounterS_ZhouQiao.Class1*/
EXEC @err = sp_OACreate ' CounterS_ZhouQiao.Class1 ' , @object out
/**/ /*2.创建失败打印错误信息*/
IF @err <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object , @src OUT, @desc OUT
SELECT Hr = CONVERT ( varbinary ( 4 ), @err ), Source = @src , Description = @desc
RETURN
END
/**/ /*3.调用如上创建实例的方法ADD, @return_value为返回值*/
EXEC @err = sp_OAMethod @object , ' GetCounter ' , @return_value OUT, @INPUT1 , @INPUT2 , @INPUT3
IF @err <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object , @src OUT, @desc OUT
SELECT Hr = CONVERT ( varbinary ( 4 ), @err ), Source = @src , Description = @desc
RETURN
END
PRINT ' 返回结果为: ' + ( @return_value ) -- 这里显示返回值
/**/ /*4.释放实例*/
EXEC sp_OADestroy @object
END
GO
-- 测试下
EXEC Test ' Budget1 ' , ' 111;20070307;1503; ' , ' ZhouQiao70;ZhouQiao70 '
DROP PROCEDURE Test
GO
-- 定义一个存储过程, 两个输入参数
CREATE PROCEDURE Test
@INPUT1 VARCHAR ( 255 ),
@INPUT2 VARCHAR ( 255 ),
@INPUT3 VARCHAR ( 255 )
AS
BEGIN
DECLARE @object INT -- 实例
DECLARE @err INT -- 是否成功
DECLARE @return_value VARCHAR ( 255 ) -- 返回值
DECLARE @src VARCHAR ( 255 ), @desc VARCHAR ( 255 ) -- 错误信息
/**/ /*1.创建COM实例, 调用CounterS_ZhouQiao.Class1*/
EXEC @err = sp_OACreate ' CounterS_ZhouQiao.Class1 ' , @object out
/**/ /*2.创建失败打印错误信息*/
IF @err <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object , @src OUT, @desc OUT
SELECT Hr = CONVERT ( varbinary ( 4 ), @err ), Source = @src , Description = @desc
RETURN
END
/**/ /*3.调用如上创建实例的方法ADD, @return_value为返回值*/
EXEC @err = sp_OAMethod @object , ' GetCounter ' , @return_value OUT, @INPUT1 , @INPUT2 , @INPUT3
IF @err <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object , @src OUT, @desc OUT
SELECT Hr = CONVERT ( varbinary ( 4 ), @err ), Source = @src , Description = @desc
RETURN
END
PRINT ' 返回结果为: ' + ( @return_value ) -- 这里显示返回值
/**/ /*4.释放实例*/
EXEC sp_OADestroy @object
END
GO
-- 测试下
EXEC Test ' Budget1 ' , ' 111;20070307;1503; ' , ' ZhouQiao70;ZhouQiao70 '