IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_ins_biztype_query]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_ins_biztype_query]
GO
create procedure [dbo].[mps_ins_biztype_query](
@cmpid int , 
@bizid int,
@caption nvarchar(100) 
) as
begin
set nocount on
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
set @caption = ISNULL(@caption,'') 
if (@caption='') set @caption='无名称' 
declare @bqlid int 
select top 1 @bqlid=bql_id from mps_biztype_query with(nolock) where bql_bizid=@bizid and bql_caption=@caption 
set @bqlid = ISNULL(@bqlid,0) 
if (@bqlid=0) 
begin
insert into mps_biztype_query(bql_bizid,bql_caption,bql_order) values(@bizid,@caption,999) 
select top 1 @bqlid=bql_id from mps_biztype_query with(nolock) where bql_bizid=@bizid and bql_caption=@caption 
set @bqlid = ISNULL(@bqlid,0) 
select * from mps_biztype_query with(nolock) where bql_bizid=@bizid  order by bql_order asc
end else 
begin
select * from mps_biztype_query with(nolock) where bql_bizid=@bizid  order by bql_order asc
end 
set nocount off 
end