update f
set f.type_ = (select e.EntityID from VCLib.T_ENTITIES e where e.[Schema] = 'VLab' and e.EntName = 'CHAT_FILE')
from VCLib.T_FILE f
	join FIES.T_CHAT_FILE cf on cf.FileID = f.FileID

INSERT INTO [VLab].[T_CHAT_FILE]
           ([FileID]
           ,[ChatDataMessage])
SELECT
            cf.FileID--<FileID, uniqueidentifier,>
           ,cf.ChatDataMessage--<ChatDataMessage, uniqueidentifier,>
from FIES.T_CHAT_FILE cf



INSERT INTO [VLab].[T_CHAT_GROUP]
           ([ChatGroupID]
           ,[CreateTime]
           ,[Name]
           ,[Creator])
SELECT
            cg.ChatGroupID--<ChatGroupID, uniqueidentifier,>
           ,cg.CreateTime--<CreateTime, datetime,>
           ,cg.Name--<Name, varchar(512),>
           ,cg.Creator--<Creator, uniqueidentifier,>)
from FIES.T_CHAT_GROUP cg



INSERT INTO [VLab].[T_CHAT_GROUP_USER]
           ([ChatGroupUserID]
           ,[AddTime]
           ,[Users]
           ,[ChatGroup])
SELECT
            cgu.ChatGroupUserID--<ChatGroupUserID, uniqueidentifier,>
           ,cgu.AddTime--<AddTime, datetime,>
           ,cgu.Users--<Users, uniqueidentifier,>
           ,cgu.ChatGroup--<ChatGroup, uniqueidentifier,>)
from FIES.T_CHAT_GROUP_USER cgu



INSERT INTO [VLab].[T_CHAT_MESSAGE]
           ([ChatMessageID]
           ,[MessageTime]
           ,[UserFrom]
           ,[UserTo]
           ,[ChatGroup]
           ,[type_])
SELECT
            cm.ChatMessageID--<ChatMessageID, uniqueidentifier,>
           ,cm.MessageTime--<MessageTime, datetime,>
           ,cm.UserFrom--<UserFrom, uniqueidentifier,>
           ,cm.UserTo--<UserTo, uniqueidentifier,>
           ,cm.ChatGroup--<ChatGroup, uniqueidentifier,>
		   ,ne.EntityID--<type_, int,>)
from FIES.T_CHAT_MESSAGE cm
	join VCLib.T_ENTITIES e on e.EntityID = cm.type_
	join VCLib.T_ENTITIES ne on ne.[Schema] = 'VLab' and ne.EntName = e.EntName

update cm
set cm.type_ = ne.EntityID
from FIES.T_CHAT_MESSAGE cm
	join VCLib.T_ENTITIES e on e.EntityID = cm.type_
	join VCLib.T_ENTITIES ne on ne.[Schema] = 'VLab' and ne.EntName = e.EntName



INSERT INTO [VLab].[T_CHAT_PINNED_USER]
           ([ChatPinnedUserID]
           ,[Users]
           ,[PinnedUser])
SELECT
            cpu.ChatPinnedUserID--<ChatPinnedUserID, uniqueidentifier,>
           ,cpu.Users--<Users, uniqueidentifier,>
           ,cpu.PinnedUser--<PinnedUser, uniqueidentifier,>)
from FIES.T_CHAT_PINNED_USER cpu



INSERT INTO [VLab].[T_CHAT_TEXT_MESSAGE]
           ([ChatMessageID]
           ,[MessageText])
SELECT
            ctm.ChatMessageID--<ChatMessageID, uniqueidentifier,>
           ,ctm.MessageText--<MessageText, varchar(max),>)
from FIES.T_CHAT_TEXT_MESSAGE ctm



INSERT INTO [VLab].[T_CHAT_USER_MESSAGE]
           ([ChatUserMessageID]
           ,[UpdateTime]
           ,[Users]
           ,[ChatMessage]
           ,[Status])
SELECT
            cum.ChatUserMessageID--<ChatUserMessageID, uniqueidentifier,>
           ,cum.UpdateTime--<UpdateTime, datetime,>
           ,cum.Users--<Users, uniqueidentifier,>
           ,cum.ChatMessage--<ChatMessage, uniqueidentifier,>
           ,cum.Status--<Status, int,>)
from FIES.T_CHAT_USER_MESSAGE cum