IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_account_item]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_account_item]
GO
create procedure [dbo].[mps_new_account_item] 
@cmpid int,
@caption nvarchar(100),
@code varchar(50)
as
begin
    set nocount on 
declare @order1 int,@aiid bigint;
--查询出最后一条排序
select top 1 @order1 = ai_order from mps_account_item
where  ai_cmpid=@cmpid order by ai_order desc 
    set @order1 = isnull(@order1 , 0) 
    set @order1 = @order1 +1
    insert into mps_account_item(ai_cmpid,ai_order,ai_caption,ai_display,ai_full,ai_code)
    values(@cmpid,@order1,@caption,@caption,@caption,@code)  
    select @aiid = @@identity
    
    --新增记录查询
    select top 1 * from mps_account_item where ai_id = @aiid

set nocount off
end