Q:

Inconsistent behavior of Min() and Max() on a varchar column

I have a table MyTable in which the below are the three major columns.
ContactId | QuestionId | ResponseValue
   8           31         Ankush Agro
   8           32         Pramod Gho
   9           31         Pawansut K S K
   9           32         sandip mor

The above ResponseValue column is a dynamic column. i.e. 
The response value changes as per the question id which refers from a questionmaster.
In other words this is what the table indirectly represents,
ContactId  |    Question    |     ResponseValue
   8           Shop Name          Ankush Agro
   8           Owner Name         Pramod Gho
   9           Shop Name          Pawansut K S K
   9           Owner Name         sandip mor

So now my requirement is that i need each Question Name in the questions column 
as a column header. i.e. Pivot the Table on Shop Name and Owner name.
Since an aggregate function cannot be used on non-numeric column i am using min() and Max() functions
Like this,
Select
max(Case MyTable.QuestionID When  '31' Then ResponseValue else 'N/A' End) [Shop Name],
max(Case MyTable.QuestionID When  '32' Then ResponseValue else 'N/A' End) [Owner Name]
from MyTable
left join QuestionMaster on QuestionMaster.QuestionId=  MyTable.QuestionId
where MyTable.QuestionId in (31,32)

The Problem that i am facing is,
if I use Max() on shopname only the second records' shopname value is displayed but the first records is 'N/A'
Shop Name      |    Owner Name
Pawansut K S K      sandip mor
   N/A              Pramod Gho

And when i use Min() Vice Versa happens
Shop Name      |    Owner Name
   N/A              sandip mor
Ankush Agro         Pramod Gho

Can some one give me an insight of why this is happening?
This is how i want my query to give the resultset
  Shop Name      |  Owner Name
   Pawansut K S K       sandip mor
    Ankush Agro         Pramod Gho

A:

Your pivot query has a problem.  You should be using NULL values in the ELSE portion of the CASE expressions:
SELECT COALESCE(MAX(CASE WHEN t1.QuestionID = '31'
                         THEN t1.ResponseValue ELSE NULL END), 'N/A') AS [Shop Name],
       COALESCE(MAX(CASE WHEN t1.QuestionID = '32'
                         THEN t1.ResponseValue ELSE NULL END), 'N/A') AS [Owner Name]
FROM MyTable t1
LEFT JOIN QuestionMaster t2
    ON t2.QuestionId = t1.QuestionId
WHERE t1.QuestionId IN (31, 32)
GROUP BY t1.QuestionId

