There's no need to transform the data in script. Just create a pivot table with SURVEY_ID (row) and TREND_ID (column) as dimensions, and Only(ANSWER) as the expression/measure. In Qlikview, pivot the TREND_ID by dragging it to the top.
Logic will get you from a to b. Imagination will take you everywhere. - A Einstein