Home All Groups Group Topic Archive Search About
Author
1 Dec 2005 7:17 PM
Dr Van Nostrand
I have the following SQL query:

"SELECT Fname AS First, Lname AS Last, Email, Address, City, State, Zip, " +
      "Company, Phone, users_surveys.Datefield as Date, " +

      "CASE WHEN questionID = 1 THEN answer ELSE NULL END AS Reseller, " +
      "CASE WHEN questionID = 2 THEN answer ELSE NULL END AS Business, " +
      "CASE WHEN questionID = 3 THEN answer ELSE NULL END AS Product, " +
      "CASE WHEN questionID = 4 THEN answer ELSE NULL END AS 'Receive
Literature' " +

    "FROM users, users_surveys " +
    "WHERE users.userID = users_surveys.userID";

-------------------

The issue is that the CASE statements put each question into a separate row.
Is there anyway to force it to all be in the same row?

TIA

Author
1 Dec 2005 8:31 PM
Alexander Kuznetsov
instead of users_surveys use an inline view :

---- untested -------

( select userID,
max(CASE WHEN questionID = 1 THEN answer ELSE NULL END) AS Reseller,
....
from users_surveys group by userID) users_surveys

---- untested -------

AddThis Social Bookmark Button