IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_update_all_logindeparttitles]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_update_all_logindeparttitles]
GO

CREATE procedure [dbo].[mps_update_all_logindeparttitles]
as
begin
set nocount on
declare @cu_ids varchar(max) 
set @cu_ids=''
select @cu_ids+=CONVERT(varchar,cu_id)+',' from mps_login
declare @index int,@sub varchar(max)
set @index=1
set @sub=''
while @index > 0
begin
set @index = CHARINDEX(',',@cu_ids)
if @index >0
begin
set @sub = SUBSTRING(@cu_ids,1,@index-1)
set @cu_ids = SUBSTRING(@cu_ids,@index+1,LEN(@cu_ids)-@index)
if(@sub>'')
exec mps_update_logindeparttitles @sub
end
end
end