1

Thank you for the reply, but again im already using dynamic fields.

For example:

DECLARE @columns VARCHAR(8000)
SELECT @columns = COALESCE(@columns + ',[' + cast(QuestionName as varchar) + ']', '[' + cast(QuestionName as varchar)+ ']')
FROM Answer A 
INNER JOIN Question Q ON A.QuestionID = Q.QuestionID
INNER JOIN Customer C ON A.CustomerID = C.CustomerID
GROUP BY Q.QuestionName

SET @columns = '[CustomerID],' + @columns

DECLARE @query VARCHAR(8000)
SET @query = 'Some PIVOT query without aggregation'

EXECUTE(@query)

But i want to arrange the fields in @columns..i want 1 field to be 1st:

@columns = [f1],[f2],[f3].

What i want is like this:

@columns = [f2],[f1],[f3] : 

Because one of the fetch data..is constant in my report.. and should be place in the beginning or the first row to be displayed.

slavoo
  • 5,798
  • 64
  • 37
  • 39
DarrelAbello
  • 9
  • 2
  • 9
  • You'll have to explicitly name the columns from `table1` instead of using `SELECT *` – NickyvV Feb 20 '14 at 08:01
  • Have a look at this trick: http://stackoverflow.com/a/1712243/1423456 – Kaarel Nummert Feb 20 '14 at 08:01
  • thank you Nicky for your reply, but i dont know the numbers of fields to be fetch,names of the fields, because it will depend on the user input., – DarrelAbello Feb 20 '14 at 08:09
  • ow..i tried that already for the other reports.. but i want to know an easy and fast way.. thank you again – DarrelAbello Feb 20 '14 at 08:15
  • You should use sql dynamique, take a look at this http://stackoverflow.com/questions/11985796/sql-server-pivot-dynamic-columns-no-aggregation. He uses dynamic sql to generate the pivot and to generate the select. As it's dynamique you can always imagine to have a where cols not like f1 and add it yourself in the constructor – Mathese F Feb 20 '14 at 10:12

0 Answers0