Crosstab

  • I posted this yesterday and have since made changes to make this easier. I am a little new to SQL and don't quite understand crosstabbing yet. I need to crosstab the contents from the following table to look like:

    Dealer District CarLine Confirmed Released Dlr Inventory

    Here is the table defination

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Inbounds] Script Date: 10/18/2013 9:23:07 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[Inbounds](

    [Car Line] [varchar](15) NULL,

    [Count] [int] NULL,

    [Dealer] [varchar](75) NULL,

    [District] [int] NULL,

    [Status] [varchar](20) NULL

    ) ON [PRIMARY]

    GO

    SET ANSI_PADDING OFF

    GO

    Here is a small sample of output data:

    Car LineCountDealerDistrictStatus

    Legacy1020125 - Don's Subaru5Confirmed

    Legacy1020125 - Don's Subaru5Released

    Forester15020125 - Don's Subaru5Confirmed

    Crosstrek6020125 - Don's Subaru5Confirmed

    Legacy2020125 - Don's Subaru5Dealer Inventory

    Outback1020125 - Don's Subaru5Released

    Outback4020128 - Van Bortel6Released

    Outback5020128 - Van Bortel6Dealer Inventory

    Legacy3020128 - Van Bortel6Dealer Inventory

    Forester1020128 - Van Bortel6Dealer Inventory

    As you can see There are 3 different status's. I do not want to sum. A count has already been done when I dumped the data into this table. The information contained in this table cam from 3 separate tables.

  • Please don't create new threads for the same issue. It fragments your replies and makes it harder for those of us trying to help you.

    The original thread is here. http://www.sqlservercentral.com/Forums/Topic1505867-2799-1.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply