You sure the sample data is corect, I mean how can response ID be both male and female?Oh, wait...I think I've heard of thatCREATE TABLE myTable99( ResponseID int , ItemText varchar(255) , AnswerValue varchar(255))GOINSERT INTO myTable99(ResponseID, ItemText, AnswerValue)SELECT 1, 'Gender', 'Male' UNION ALLSELECT 1, 'Ethnicity', 'White' UNION ALLSELECT 1, 'Smokes', 'Yes' UNION ALLSELECT 2, 'Ethnicity', 'Spanish' UNION ALLSELECT 2, 'Ethnicity', 'White' UNION ALLSELECT 2, 'Gender', 'Female' UNION ALLSELECT 2, 'Gender', 'Male' UNION ALLSELECT 3, 'Smokes', 'Yes' UNION ALLSELECT 4, 'Gender', 'Female'GO SELECT a.ResponseID, Gender, Ethnicity, Smokes FROM (SELECT DISTINCT ResponseID FROM myTable99) AS aLEFT JOIN (SELECT ResponseID, AnswerValue AS Gender FROM myTable99 WHERE ItemText = 'Gender' ) AS b ON b.ResponseID = a.ResponseIDLEFT JOIN (SELECT ResponseID, AnswerValue AS Ethnicity FROM myTable99 WHERE ItemText = 'Ethnicity') AS c ON c.ResponseID = a.ResponseIDLEFT JOIN (SELECT ResponseID, AnswerValue AS Smokes FROM myTable99 WHERE ItemText = 'Smokes' ) AS d ON d.ResponseID = a.ResponseID
Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam