奇怪的SQL bug IIS 7

I have recently had to amend the following SQL to this:

$this->db->select('StaffMembers.Id AS StaffMembers_Id, Contacts.AssociatedStaffMember_Id');
$this->db->join("StaffMembers", "Contacts.AssociatedStaffMember_Id=StaffMembers.Id");                   
$q1 = $this->db->get_where($this->contacts_table, 'Contacts.AssociatedStaffMember_Id ='.$ContactId);
$s = $q1->row_array(); 

YET when I log in,it displays an old SQL:

A Database Error Occurred
Error Number:

Invalid column name 'Contact_Id'.

SELECT Contacts.Id, StaffMembers.Id AS StaffMember_Id 
FROM StaffMembers JOIN Contacts ON Contacts.Id=StaffMembers.Contact_Id 
WHERE Contacts.Id =161

I have restarted mssql server, flushed memcached and iis7, but it is still showing the old query. No idea, why on earth it is doing this, any thoughts?

Found the problem, there seemed to be some duplicate SQL in a controller class (when there shouldn't be!)

Fixed that - problem was resolved. Cheers.

Does this resolve the issue in any way?

$this->db->select('StaffMembers.Id AS StaffMembers_Id, Contacts.AssociatedStaffMember_Id');
$this->db->join("StaffMembers", "Contacts.AssociatedStaffMember_Id=StaffMembers.Id");  
$this->db->where('Contacts.AssociatedStaffMember_Id', $ContactId);
$q1 = $this->db->get($this->contacts_table);
$s = $q1->row_array();

Your previous code was using get_where and I'm not 100% sure if that can be mixed.

Do you have an underlying class that manipulates the $this->db class before you run this code?

Gav