I did not try to repro this myself, but I can guess what is going on. sp_describe_parameter_encryption presumably looks at the metadata that is generated at compile-time. The problem is that at this point the temp table does not exist. However, this does not result in an error, since SQL Server employs deferred name resolution for tables. That is, if table does not exist, when SQL Server tries to compile a query, it does not raise error. It is not until the statement is reach at run-time you get an error.
When you have a table variable it is a different matter, since the table variable is a declared entity.
You can test my hypothesis this way:
CREATE TABLE #AvailablePatients (
PatientID INT NOT NULL
PRIMARY KEY (PatientID)
)
exec sp_describe_parameter_encryption
N'
DECLARE @AvailablePatients TABLE (
PatientID INT NOT NULL
PRIMARY KEY (PatientID)
)
SELECT [SSN], Patients.[FirstName], Patients.[LastName], [BirthDate]
FROM Patients
INNER JOIN @AvailablePatients AS AvailablePatients ON AvailablePatients.PatientID = Patients.PatientID
WHERE SSN=@SSN',
N'
@SSN char(11)'
That is you create the temp table before you call sp_describe_parameter_encryption . Because the temp table exists, SQL Server will now perform full binding.
Note that I am not suggesting this is a workaround, because I realise that it is not really practical to do this in your application. This would be to test my theory.