如何从存储过程中获取消息 [英] How Do I Take Message From The Stored Procedure
问题描述
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屋!