SQL Pivot statement

Posted on 2011-10-31
Last Modified: 2012-05-12
Is there any way the attached select can be done where I just grab all values in the disqualifyReason columns without having to actually declare them?

I don't want to have to put the...
[Qualified], [DebtConsol], [Disability],....etc...

unless I have to

SELECT rep, [Qualified], [DebtConsol], [Disability], [Loans], [Lottery], [needLegal] , [PreSettlement], [Restitution], [RetVet], [SocialSecurity], [WorkComp], [ExistsTransferred] 
into #tempData FROM CALLDETAIL.dbo.inboundCalls T
 pivot (COUNT(disqualifyReason) 
			FOR disqualifyReason IN ([Qualified], [DebtConsol], [Disability], [Loans], [Lottery], [needLegal], [PreSettlement], [Restitution], [RetVet], [SocialSecurity], [WorkComp], [ExistsTransferred])) pvt;

Open in new window

Question by:lrbrister
    LVL 92

    Accepted Solution


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    760 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

    13 Experts available now in Live!

    Get 1:1 Help Now