CREATE PROCEDURE [dbo].[up_read_all_guild] @server int as begin set nocount on set transaction isolation level read uncommitted --select guild_id, room_id from GuildTable where [group_id] = @server and [block_type] = 0 SELECT T.[guild_id], T.[room_id] FROM GuildTable AS T WITH (NOLOCK) INNER JOIN ( SELECT M.[guild_id], count(M.[guild_id]) AS member_cnt FROM GuildMemberTable AS M WITH (NOLOCK) GROUP BY M.[guild_id] HAVING count(M.[guild_id])>0 ) AS C ON C.[guild_id]=T.[guild_id] AND T.[group_id]=@server AND T.[block_type]=0 end