IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_privategroup]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_privategroup]
GO
CREATE procedure [dbo].[mps_new_privategroup](
@cmpid int ,
@bcid int,
@groupname nvarchar(200) 
)
as 
begin
set nocount on
if (exists (select * from mps_privategroup where pg_cmpid=@cmpid and pg_name=@groupname)) 
begin
select 0 none where 0=1
end else 
begin
if (@bcid>0)  -- 此时是某分公司的人来建分组，那就只能建自己分公司的
begin
insert into mps_privategroup(pg_cmpid,pg_bcid,pg_name) values(@cmpid,@bcid,@groupname)
end else 
begin
insert into mps_privategroup(pg_cmpid,pg_bcid,pg_name) values(@cmpid,0,@groupname)
end 
select * from mps_privategroup where pg_cmpid=@cmpid and pg_name=@groupname 
end
set nocount off
end