![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
CREATE proc AddVisitReportId --定义参数 @sql varchar(max), @ClientName varchar(max), @MonthlyAccount varchar(max), @ProAmount decimal, @ProductId int, @ProfessionId int, @VisitKindId int, @PhraseId int, @StaffId int, @Remark varchar(max), @CustomerName varchar(max) as begin SET NOCOUNT ON; DECLARE @ERR int DECLARE @Id int SET @ERR = 0; SET @Id = 0 begin tran begin try --编写sql语句 insert into [dbo].[T_VisitReport] values( @ClientName ,@MonthlyAccount ,@ProAmount ,@ProductId ,@ProfessionId ,@VisitKindId ,@PhraseId ,@StaffId ,GETDATE()) set @Id=@@IDENTITY EXEC(@sql); insert into [dbo].[T_Remark] values( @Id ,@Remark ,GETDATE() ,@CustomerName) end try begin catch SET @ERR = @ERR + 1 end catch IF (@ERR = 0) BEGIN COMMIT TRAN RETURN 1 END ELSE BEGIN ROLLBACK TRAN RETURN -1 END end
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
DECLARE @return_value int EXEC @return_value = [dbo].[AddVisitReport] @sql = 'select * from [dbo].[T_Product]', @ClientName = 'aaaa', @MonthlyAccount = '44000000', @ProAmount = 100, @ProductId = 1, @ProfessionId = 1, @VisitKindId = 1, @PhraseId = 1, @StaffId = 6, @Remark ='aaaaa', @CustomerName = 'aaaaaa' SELECT 'Return Value' = @return_value GO