sql server - Confused reading / attempting VERY simple SQL Pivot...aggregation required? -


I have a table where multiple rows are needed to be used as columns, Google tells that PIVOT is just like this It is a matter of fact that I start by reading it looks straight ahead and mentions it ...

and makes aggregation where they are needed

I will start writing my own spindle only to the examples which all use aggregation works. So I go back to Google for some other examples that can not use aggregation and every instance is using aggregation ... so I was wondering if I had read the definition correctly? I thought the aggregation was not available right now.

And do aggregations where they are necessary .... but I do not need any kind ....?

My table looks like this:

  SELECT * FROM [ADHOC_FIELD] where TEMPLATE_ID = 356 CONTACT_ID | FIELD_NAME | TEMPLATE_ID | VALUE ROW_ID 1017674 Orig_Name 356 John 1st 1017674 @ Orig_EMail 356 Com 1 1017674 Orig_Trans 356 ABC 1 1017674 Orig_WIDID 356 1001 1 I would like to present the data like this:  
  CONTACT_ID | Orig_Name | Orig_Email | Orig_Trans | As I have written, so I was motivated with many posts about the axis without any aggregation, but they were more complex than my simple little requirement.     P> It sounded like a winner, but still they use row_number and then MAX functions MAX?  

So I'm not asking anyone to try to understand my work .... PIVOT requires aggregation or not?

Edit


So based on everyone's response, I wrote it in the first Zof Dino Answer. [SELECT VALUE, ROW_NUMBER ()] [code] SELECT [1] AS 'recv_date', [2] AS 'send_date', [3] AS 'proc_name', ... etc According to CONTACT_ID ADHOC_FIELD] WHERE TEMPLATE_ID = 356) Source PIVOT (MAX (VALUE) for IN ([1], [2], [3], ...)) PIV

And it was working, but only 1 record is coming back. Although Zof Dino said that I am not quite straightforward in my thinking and his answer is correct.

is. In these cases, MAX is often used. You can also use MIN for the same effect. For FILED_NAME IN (Orig_Name) ADHOC_FIELD can use CONTACT_ID, Orig_Name, Orig_Email, Orig_Trans, Orig_WFID from PIVOT (MAX) (value). , OrigIEmail, Orig_Trans, Orig_WFID)) Private WHERE PV .EMPLATE_ID = 356

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -