--UQ_dept_Uf_ILC_CostCodeType IF NOT EXISTS (SELECT TOP 1 1 FROM ObjectMainMessages WHERE ObjectName = 'UQ_dept_Uf_ILC_CostCodeType' AND MessageType = 17) BEGIN DECLARE @NextMessageNo int SELECT @NextMessageNo = ISNULL(MAX(messageno),799999) FROM ApplicationMessages WHERE MessageNo BETWEEN 800000 AND 999999 SET @NextMessageNo = @NextMessageNo + 1 --add main message 100093 = The &1 entered already exists. EXEC AddObjectMainMessageSp 'UQ_dept_Uf_ILC_CostCodeType', 17, 100093, 16, 'Dept Cost Code Type UQ violation', 0 --add the substitution text EXEC AddApplicationMessageSp @NextMessageNo, 'Cost Code Type', N'1033' --add substitution text to main message EXEC AddObjectBuildMessageSp 'UQ_dept_Uf_ILC_CostCodeType', 17, 1, @NextMessageNo END