Joe Joe - 1 year ago 89
SQL Question

What does P mean after the from clause in SQL

I am try to make sense of this SQL code that compiles fine.

(SELECT [eeeConfigurationId], [TimeInterval]
FROM [dbo].[eeeConfiguration]) P
(MAX([TimeInterval]) FOR [eeeConfigurationId] IN
[41],[42],[43],[44],[45],[46],[47],[48],[49],[50]) )PV

What does that
after the from clause mean? And
at the end?

I inherited code that says I should get a list in C# but SQL Server says int?

Never seen this before. I tried googling.

jpw jpw
Answer Source

They are the names used for the derived tables.

P is <alias for the source query> and PV is <alias for the pivot table>.

The syntax for the pivot statement is as follows:

SELECT <non-pivoted column>,    
    [first pivoted column] AS <column name>,    
    [second pivoted column] AS <column name>,    
    [last pivoted column] AS <column name>    
    (<SELECT query that produces the data>)    
    AS <alias for the source query>    
    <aggregation function>(<column being aggregated>)    
[<column that contains the values that will become column headers>]    
    IN ( [first pivoted column], [second pivoted column],    
    ... [last pivoted column])    
) AS <alias for the pivot table>    
<optional ORDER BY clause>;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download