I have a column with answers that people responded to different questions about themseleves. I have another column with the question id that the answer corresponds to. i want to display the answers in separate columns based on which question it corresponds to. Each column should be filled with the answers to the specific question. I used a case statement to divide the answer column into different columns based on their question id. The problem is that i don't know what to put after the else. if i put Null, then i have a lot of empty fields that say null. I want that the fields shouldn't show up all together.
Here is my query:
TOP (100) PERCENT dbo.ProfileAnswers.u_username AS Username, CASE ProfileAnswers.pq_id WHEN 101 THEN ProfileAnswers.pa_value ELSE NULL
END AS HebrewName, CASE ProfileAnswers.pq_id WHEN 42 THEN ProfileAnswers.pa_value ELSE NULL END AS 'Learing/Working',
CASE ProfileAnswers.pq_id WHEN 70 THEN ProfileAnswers.pa_value ELSE NULL END AS 'Previously Married',
CASE ProfileAnswers.pq_id WHEN 35 THEN ProfileAnswers.pa_value ELSE NULL END AS Type, dbo.ProfileAnswers.pa_approved AS Approved,
DATEDIFF(Year, dbo.Users.u_birthdate, GETDATE()) AS Age
FROM dbo.ProfileAnswers INNER JOIN
dbo.Users ON dbo.ProfileAnswers.u_username = dbo.Users.u_username
WHERE (dbo.Users.u_gender = 2)
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!