如何从存储过程中获取消息 [英] How Do I Take Message From The Stored Procedure

查看:88
本文介绍了如何从存储过程中获取消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALTER程序[dbo]。[GetSubmitDetails]



@cust_id int,

@name varchar(50),

@state Varchar(50),

@s_amount varchar(50),

@sales_id int,

@select out







AS

声明@count int

设置@count =(SELECT count(*)FROM customer inner join

sales

on customer.cust_id = sales.cust_id

WHERE customer.cust_id = @cust_id

和sales.sales_id=@sales_id)

if(@ count> 0)

BEGIN



SELECT'此记录已存在!'

结束

ELSE



BEGIN





选择'加入记录'

插入test.dbo 。[customer](cust_id,name,[state])值(@ cust_id,@ name,@ state)



插入test.dbo。[sales]( cust_id,sales_id,s_amount)值(@ cust_id,@ sales_id,@ s_amount)

END

解决方案

创建一个新的存储过程并在此过程中编写exec代码,您将获得上一个过程的消息,然后继续执行代码。

 创建  procedure  GetReturnValue 
as
开始
声明 @ result as varchar 50
exec @ result = [dbo]。[GetSubmitDetails] @cust_id @ name @ state @s_amount @ sales_id @ selectout


ALTER procedure [dbo].[GetSubmitDetails]
(
@cust_id int ,
@name varchar (50),
@state Varchar (50),
@s_amount varchar (50),
@sales_id int,
@select out

)

AS
declare @count int
set @count = (SELECT count(*) FROM customer inner join
sales
on customer.cust_id=sales.cust_id
WHERE customer.cust_id = @cust_id
and sales.sales_id=@sales_id)
if(@count>0)
BEGIN

SELECT 'This record already exists!'
END
ELSE

BEGIN


SELECT 'Record Added'
Insert into test.dbo.[customer](cust_id,name,[state]) values (@cust_id,@name,@state)

Insert into test.dbo.[sales](cust_id,sales_id,s_amount) values (@cust_id,@sales_id,@s_amount)
END

解决方案

Create One new Stored Procedure and write exec code inside this procedure, you will get the message of that previous procedure and then you proceed your code.

create procedure GetReturnValue
as
begin
declare @result as varchar(50)
exec @result=[dbo].[GetSubmitDetails] @cust_id,@name,@state,@s_amount,@sales_id,@selectout 
end


这篇关于如何从存储过程中获取消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆