Fatal error 3624 : iKey GetKeyCount() I am receiving errors when I run the following query:

SELECT (
        SELECT 1
        FROM dbo.AccountEntry AE
        WHERE AE.Account = P.Account
        )
FROM dbo.Proposal P
WHERE P.id = @Id


When run via ADO.NET it gives:


  Warning: Fatal error 3624 occurred at Jun 20 2016 2:28AM. Note the
  error and time, and contact your system administrator. A severe error
  occurred on the current command. The results, if any, should be
  discarded.


When run in SSMS it gives


  Location:  statutil.cpp:4128
  Expression:    iKey &lt; m_statBlob.GetHeader()->GetKeyCount()
  SPID:      59 Process ID:  1732
  Msg
  3624, Level 20, State 1, Line 1
  A system assertion check has failed.
  Check the SQL Server error log for details. Typically, an assertion
  failure is caused by a software bug or data corruption. To check for
  database corruption, consider running DBCC CHECKDB. If you agreed to
  send dumps to Microsoft during setup, a mini dump will be sent to
  Microsoft. An update might be available from Microsoft in the latest
  Service Pack or in a QFE from Technical Support.
  Msg 0, Level 20,
  State 0, Line 0
  A severe error occurred on the current command.  The
  results, if any, should be discarded.


Interestingly this code works when setting @Account to P.Account:

select 1 from dbo.AccountEntry AE where AE.Account = @Account


I have tried restarting the server.

I have tried dropping all indexes and statistics.

I have run DBCC CHECKDB and it returns no errors.

We don't believe anything has been changed about the server since Friday when it was running happily.

SQL Version: Microsoft SQL Server 2012 - 11.0.5343.0 (X64)   May  4 2015 19:11:32   Copyright (c) Microsoft Corporation  Standard Edition (64-bit) on Windows NT 6.2  (Build 9200: ) (Hypervisor)
This issue is to do with corrupt/invalid statistics.

A specific case where it can occur is mentioned in this connect item


  The Metadata of disabled Non-Clustered Indexes becomes invalid, if you
  change the keys of the Clustered Index, and this caused the failure
  that you experienced.


With the workaround being to drop the disabled indexes.

If the situation above doesn't apply to you then try and find out the specific table with the problem hopefully dropping the statistics on this specific table or both tables if you can't pinpoint the problem one should do the job (and then recreate the stats if required). 

If neither of the above work then probably time to open a case with Microsoft PSS.

Also you appear to be on SP2 + Security Bulletin MS15-058. There have been a lot of cumulative updates and another service pack since then. Possibly the issue you are experiencing is already fixed in one of these.