CREATE PROCEDURE `spCreateChatList` ( IN `P_FromUserId` INTEGER , IN `P_FromRoleTypeId` INTEGER , IN `P_ToUserId` INTEGER , IN `P_ToRoleTypeId` INTEGER , IN `P_GroupId` INTEGER , IN `P_ChatDetail` VARCHARACTER (?) , IN `P_BatchId` INTEGER , IN `P_ContentPath` VARCHARACTER (?) ) BEGIN DECLARE `ChatId` INTEGER DEFAULT ? ; IF EXISTS ( SELECT ? FROM `tchatgroupmaster` WHERE `BatchId` = `P_BatchId` OR `P_GroupId` = ? ) THEN IF `P_ContentPath` IS NULL THEN BEGIN INSERT INTO `tchat` ( `ChatGroupId` , `ToRoleTypeId` , `ToUserId` , `FromRoleTypeId` , `FromUserId` , `ChatDetail` , `CreatedUserId` , `CreatedDateTime` ) VALUES ( `P_GroupId` , `P_ToRoleTypeId` , `P_ToUserId` , `P_FromRoleTypeId` , `P_FromUserId` , `P_ChatDetail` , ( SELECT `IFNULL` ( `CreatedUserId` , ? ) FROM `tchatgroupmaster` WHERE `Id` = `P_GroupId` ) , NOW ( ) ) ; SELECT `LAST_INSERT_ID` ( ) ; END ; ELSE BEGIN INSERT INTO `tchat` ( `ChatGroupId` , `ToRoleTypeId` , `ToUserId` , `FromRoleTypeId` , `FromUserId` , `CreatedUserId` , `CreatedDateTime` ) VALUES ( `P_GroupId` , `P_ToRoleTypeId` , `P_ToUserId` , `P_FromRoleTypeId` , `P_FromUserId` , ( SELECT `IFNULL` ( `CreatedUserId` , ? ) FROM 