IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_update_logindeparttitles]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_update_logindeparttitles]
GO
CREATE procedure [dbo].[mps_update_logindeparttitles]
@cu_id int
as
begin
set nocount on
 
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 
declare @depart_title varchar(max)
set @depart_title = ''
select @depart_title += case when CHARINDEX(lgu_depart+'.' + lgu_title,@depart_title) = 0 then lgu_depart+'.' + lgu_title +',' else '' end from mps_login_role where lgu_cuid=@cu_id
if LEN(@depart_title) >0
set @depart_title = SUBSTRING(@depart_title,1,LEN(@depart_title)-1)


update mps_login set cu_departtitles =@depart_title
where cu_id=@cu_id and cu_type = 0
end


/*

exec mps_update_logindeparttitles 1
select * from mps_login where cu_id = 1

*/