USE rt 
DECLARE @UserName NVARCHAR(50)
DECLARE @GroupID DECIMAL(18,0)

SET @UserName = N'ali'
SET @GroupID = 1

IF EXISTS(SELECT     dbo.tblUsers.IUserName, dbo.tblGroups.GroupID
FROM         dbo.tblGroups INNER JOIN
                      dbo.tblUsers ON dbo.tblGroups.GroupCreatorID = dbo.tblUsers.IUserID
WHERE     (dbo.tblUsers.IUserName = @UserName) AND (dbo.tblGroups.GroupID = @GroupID))
BEGIN
	DELETE FROM [tblMessageToGroups]       WHERE GroupID = @GroupID
	DELETE FROM [tblGroupMembers]  WHERE GroupID = @GroupID 
	DELETE FROM [tblGroups]  WHERE GroupID = @GroupID
END
GO





