Pivot Table

Posted on 2007-08-08
Last Modified: 2010-03-19
Can I use the SQL from Access below exactly the same in a stored Proc?  I do not have access to test in SQL Server right now.

TRANSFORM Count(AllStat.Position) AS CountOfPosition
SELECT AllStat.[Position Status]
FROM AllStat
GROUP BY AllStat.[Position Status]
PIVOT AllStat.Age;
Question by:LiCann
    LVL 42

    Expert Comment

    >Can I use the SQL from Access below exactly the same in a stored Proc?

    No, that syntax is not valid in TSQL

    LVL 42

    Accepted Solution

    Furthermore, TSQL does not have anything equivalent to the PIVOT clause, which determines column headings from a data column.  TSQL has a PIVOT statment, but it requires hardcoded column headings.   However, you can emulate the TRANSFORM functionality by using dynamic SQL to construct a SELECT statement with a PIVOT clause.

    If you search for "dynamic pivot" in this forum you will find examples.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now