Relate 3 tables and do a count on each...See body for more specific details

  • I need help I'm am stuck an need to complete today. Here's the set up

    I have 3 tables Confirmed, Released, and Dlr Inventory. Each can have upto 8 different models and upto 65 dealers that can have these models.Each line accounts for one vehicle. I imported each table as an .xls and appear like this:

    [Ship To Dealer],[Car Line],Status

    **The status us either Released, Dlr Inventory or Confirmed**

    I need to show as:

    [Ship To Dealer],[Car Line],Status,Count

    I have tried Union all, derived tables, joins....you name it. I just can't get it.

    A little help please.

    Adam

  • arosenbaum (10/17/2013)


    I need help I'm am stuck an need to complete today. Here's the set up

    I have 3 tables Confirmed, Released, and Dlr Inventory. Each can have upto 8 different models and upto 65 dealers that can have these models.Each line accounts for one vehicle. I imported each table as an .xls and appear like this:

    [Ship To Dealer],[Car Line],Status

    **The status us either Released, Dlr Inventory or Confirmed**

    I need to show as:

    [Ship To Dealer],[Car Line],Status,Count

    I have tried Union all, derived tables, joins....you name it. I just can't get it.

    A little help please.

    Adam

    Hi and welcome to the forums. Unfortunately your question does not contain anywhere near enough information to offer much help. In order to help we will need a few things:

    1. Sample DDL in the form of CREATE TABLE statements

    2. Sample data in the form of INSERT INTO statements

    3. Expected results based on the sample data

    Please take a few minutes and read the first article in my signature for best practices when posting questions.

    _______________________________________________________________

    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/

  • OK so my answer is cross tab it, but I am still lost. This example uses sum and I need to use count so I am thrown. Would you be willing to do a goto meeting to help me out?

  • Post enough information so that people can help you.

    1. Table definitions (right-click, script CREATE TABLE... to clipboard)... paste here.

    2. Some data (a few records - enough so we know what you're dealing with and can re-create it.)

    3. expected outcome.

    If this is a simple count, this should be really easy.. but without details, it's hard to know.

  • If these are columns in your query...

    [Ship To Dealer],[Car Line],Status,Count

    SELECT [Ship To Dealer],[Car Line],[Status] As BadReservedWord, COUNT(*) AS LineCount

    FROM MyTable

    ORDER BY [Ship To Dealer],[Car Line],[Status]

    GROUP BY [Ship To Dealer],[Car Line],[Status]

  • Here is my code:

    select *

    from

    (select [Ship To Dealer],[Status],[Car Line]

    from [Dlr Inventory]

    WHERE [Dlr Inventory].[Ship To Dealer]<>'020177' and [Dlr Inventory].von is not null and [Dlr Inventory].[Delivery Date] is null

    union all

    select [Ship To Dealer],[Status], [Car Line]

    from Released

    WHERE Released.[Ship To Dealer]<>'020177'

    union all

    select Dealer,[Status],[Car Line]

    from Confirmed

    WHERE left(confirmed.Dealer,6)<>'020177') as Inbounds

    And My Output:

    020113 - Feder SubaruConfirmedBRZ

    020113 - Feder SubaruConfirmedForester

    020113 - Feder SubaruConfirmedWRX/STi

    020113 - Feder SubaruConfirmedLegacy

    020113 - Feder SubaruConfirmedLegacy

    020113 - Feder SubaruConfirmedLegacy

    020113 - Feder SubaruConfirmedCrosstrek

    020113 - Feder SubaruConfirmedOutback

    020113 - Feder SubaruConfirmedForester

    020113 - Feder SubaruConfirmedCrosstrek

    020113 - Feder SubaruConfirmedForester

    020113 - Feder SubaruConfirmedForester

    020113 - Feder SubaruConfirmedForester

    020113 - Feder SubaruConfirmedForester

    I need to look like this:

    Dealer Carline Confirmed Released Dlr Inventory

    so i need to count number of carlines with a particular status for a particular dealer. Obviously my code is a derived table from 3 separate tables. There are many more columns in each table, but I am only selecting those I need. The last 3 columns above need to be a count number. The only difference between any of the 3 tables is the column name dealer as opposed to Ship To Dealer on the other two.

  • As we have said already. Provide ddl and some sample data. This isn't a difficult query but with nothing to work with it is next to impossible.

    _______________________________________________________________

    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/

  • Here are the 3 tables I am using. Is this what you're looking for? Is there no easy way to "union all" all 3 tables, make a derived table from that and cross tab creating 3 columns one for each status.

    Table1

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Confirmed] Script Date: 10/18/2013 8:43:44 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Confirmed](

    [VAN] [nvarchar](255) NULL,

    [VIN Key] [nvarchar](255) NULL,

    [VIN No] [nvarchar](255) NULL,

    [D# C#] [float] NULL,

    [Dealer] [nvarchar](255) NULL,

    [Car Model] [nvarchar](255) NULL,

    [Color] [nvarchar](255) NULL,

    [CPO] [nvarchar](255) NULL,

    [Status] [nvarchar](255) NULL,

    [Confirmed] [bit] NOT NULL,

    [Old Dealer] [nvarchar](255) NULL,

    [S#O#] [nvarchar](255) NULL,

    [Allocation Run] [nvarchar](255) NULL,

    [SO Customer Name] [nvarchar](255) NULL,

    [Allocation Memo] [nvarchar](255) NULL,

    [Car Model Description] [nvarchar](255) NULL,

    [Model Year] [float] NULL,

    [Car Line] [nvarchar](255) NULL,

    [A#R# Target Month] [float] NULL,

    [A#R# Target Year] [float] NULL,

    [P#R#] [nvarchar](255) NULL,

    [Tag] [nvarchar](255) NULL,

    [UID] [nchar](25) NULL

    ) ON [PRIMARY]

    GO

    Table 2

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Dlr Inventory] Script Date: 10/18/2013 8:44:28 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Dlr Inventory](

    [VIN Key] [nvarchar](255) NULL,

    [VAN] [nvarchar](255) NULL,

    [Status] [nvarchar](255) NULL,

    [Car Model] [nvarchar](255) NULL,

    [Car Color] [nvarchar](255) NULL,

    [VON] [nvarchar](255) NULL,

    [VIN Number] [nvarchar](255) NULL,

    [Last Company Inventory] [nvarchar](255) NULL,

    [Car Model Description] [nvarchar](255) NULL,

    [District] [float] NULL,

    [SO Number] [nvarchar](255) NULL,

    [SO Date] [datetime] NULL,

    [S#O# Customer] [nvarchar](255) NULL,

    [AR Target] [nvarchar](255) NULL,

    [VAN Priority] [nvarchar](255) NULL,

    [Model Year] [float] NULL,

    [Car Line] [nvarchar](255) NULL,

    [Car Tag] [nvarchar](255) NULL,

    [Ship Number] [nvarchar](255) NULL,

    [Rail Number] [nvarchar](255) NULL,

    [Load Number] [nvarchar](255) NULL,

    [Ship Away Lane] [nvarchar](255) NULL,

    [Key Number] [nvarchar](255) NULL,

    [Transmission] [nvarchar](255) NULL,

    [Body Type] [nvarchar](255) NULL,

    [Engine Number] [nvarchar](255) NULL,

    [Car Spec] [nvarchar](255) NULL,

    [Stop Sale] [bit] NOT NULL,

    [Out Of Region] [bit] NOT NULL,

    [Ship To Dealer] [nvarchar](255) NULL,

    [Location] [nvarchar](255) NULL,

    [Case Number] [nvarchar](255) NULL,

    [Demo Reg#] [datetime] NULL,

    [Mix Id] [nvarchar](255) NULL,

    [Final Assembly Point] [nvarchar](255) NULL,

    [Mileage] [float] NULL,

    [Trans# Org#] [nvarchar](255) NULL,

    [Engine Org#] [nvarchar](255) NULL,

    [Rail Shipped] [datetime] NULL,

    [Truck Shipped] [datetime] NULL,

    [Port] [nvarchar](255) NULL,

    [Release Priority] [bit] NOT NULL,

    [Released To DAI] [datetime] NULL,

    [Paid SOA Date] [datetime] NULL,

    [DAI Scheduled] [datetime] NULL,

    [MNR Print Date] [datetime] NULL,

    [Pick Up Rail Date] [datetime] NULL,

    [Receipt Date] [datetime] NULL,

    [Receiving Driver #] [nvarchar](255) NULL,

    [Origin] [nvarchar](255) NULL,

    [Inventory Location] [nvarchar](255) NULL,

    [Parts Throw] [datetime] NULL,

    [Ship Away Lane Date] [datetime] NULL,

    [Pickup Date] [datetime] NULL,

    [Delivery Date] [datetime] NULL,

    [Subj To Inspection] [nvarchar](255) NULL,

    [DATs Import] [datetime] NULL,

    [61B Import] [datetime] NULL,

    [62B Import] [datetime] NULL,

    [Price Frozen Date] [datetime] NULL,

    [Invoiced] [nvarchar](255) NULL,

    [Shipping Zone] [nvarchar](255) NULL,

    [Accessory Complete] [datetime] NULL,

    [PDI Complete] [datetime] NULL,

    [UID] [nchar](25) NULL

    ) ON [PRIMARY]

    GO

    Table 3

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Released] Script Date: 10/18/2013 8:44:44 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Released](

    [VIN Key] [nvarchar](255) NULL,

    [VAN] [nvarchar](255) NULL,

    [Status] [nvarchar](255) NULL,

    [Car Model] [nvarchar](255) NULL,

    [Car Color] [nvarchar](255) NULL,

    [VON] [nvarchar](255) NULL,

    [VIN Number] [nvarchar](255) NULL,

    [Last Company Inventory] [nvarchar](255) NULL,

    [Car Model Description] [nvarchar](255) NULL,

    [District] [nvarchar](255) NULL,

    [SO Number] [nvarchar](255) NULL,

    [SO Date] [datetime] NULL,

    [S#O# Customer] [nvarchar](255) NULL,

    [AR Target] [nvarchar](255) NULL,

    [VAN Priority] [float] NULL,

    [Model Year] [float] NULL,

    [Car Line] [nvarchar](255) NULL,

    [Car Tag] [nvarchar](255) NULL,

    [Ship Number] [nvarchar](255) NULL,

    [Rail Number] [nvarchar](255) NULL,

    [Load Number] [nvarchar](255) NULL,

    [Ship Away Lane] [nvarchar](255) NULL,

    [Key Number] [nvarchar](255) NULL,

    [Transmission] [nvarchar](255) NULL,

    [Body Type] [nvarchar](255) NULL,

    [Engine Number] [nvarchar](255) NULL,

    [Car Spec] [nvarchar](255) NULL,

    [Stop Sale] [bit] NOT NULL,

    [Out Of Region] [bit] NOT NULL,

    [Ship To Dealer] [nvarchar](255) NULL,

    [Location] [nvarchar](255) NULL,

    [Case Number] [nvarchar](255) NULL,

    [Demo Reg#] [datetime] NULL,

    [Mix Id] [nvarchar](255) NULL,

    [Final Assembly Point] [nvarchar](255) NULL,

    [Mileage] [float] NULL,

    [Trans# Org#] [nvarchar](255) NULL,

    [Engine Org#] [nvarchar](255) NULL,

    [Rail Shipped] [datetime] NULL,

    [Truck Shipped] [datetime] NULL,

    [Port] [nvarchar](255) NULL,

    [Release Priority] [bit] NOT NULL,

    [Released To DAI] [datetime] NULL,

    [Paid SOA Date] [datetime] NULL,

    [DAI Scheduled] [datetime] NULL,

    [MNR Print Date] [datetime] NULL,

    [Pick Up Rail Date] [datetime] NULL,

    [Receipt Date] [datetime] NULL,

    [Receiving Driver #] [nvarchar](255) NULL,

    [Origin] [nvarchar](255) NULL,

    [Inventory Location] [nvarchar](255) NULL,

    [Parts Throw] [datetime] NULL,

    [Ship Away Lane Date] [datetime] NULL,

    [Pickup Date] [datetime] NULL,

    [Delivery Date] [datetime] NULL,

    [Subj To Inspection] [nvarchar](255) NULL,

    [DATs Import] [datetime] NULL,

    [61B Import] [datetime] NULL,

    [62B Import] [datetime] NULL,

    [Price Frozen Date] [datetime] NULL,

    [Invoiced] [nvarchar](255) NULL,

    [Shipping Zone] [nvarchar](255) NULL,

    [Accessory Complete] [datetime] NULL,

    [PDI Complete] [datetime] NULL,

    [UID] [nchar](25) NULL

    ) ON [PRIMARY]

    GO

  • Here are the 3 tables I am using. Is this what you're looking for? Is there no easy way to "union all" all 3 tables, make a derived table from that and cross tab creating 3 columns one for each status.

    Table1

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Confirmed] Script Date: 10/18/2013 8:43:44 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Confirmed](

    [VAN] [nvarchar](255) NULL,

    [VIN Key] [nvarchar](255) NULL,

    [VIN No] [nvarchar](255) NULL,

    [D# C#] [float] NULL,

    [Dealer] [nvarchar](255) NULL,

    [Car Model] [nvarchar](255) NULL,

    [Color] [nvarchar](255) NULL,

    [CPO] [nvarchar](255) NULL,

    [Status] [nvarchar](255) NULL,

    [Confirmed] [bit] NOT NULL,

    [Old Dealer] [nvarchar](255) NULL,

    [S#O#] [nvarchar](255) NULL,

    [Allocation Run] [nvarchar](255) NULL,

    [SO Customer Name] [nvarchar](255) NULL,

    [Allocation Memo] [nvarchar](255) NULL,

    [Car Model Description] [nvarchar](255) NULL,

    [Model Year] [float] NULL,

    [Car Line] [nvarchar](255) NULL,

    [A#R# Target Month] [float] NULL,

    [A#R# Target Year] [float] NULL,

    [P#R#] [nvarchar](255) NULL,

    [Tag] [nvarchar](255) NULL,

    [UID] [nchar](25) NULL

    ) ON [PRIMARY]

    GO

    Table 2

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Dlr Inventory] Script Date: 10/18/2013 8:44:28 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Dlr Inventory](

    [VIN Key] [nvarchar](255) NULL,

    [VAN] [nvarchar](255) NULL,

    [Status] [nvarchar](255) NULL,

    [Car Model] [nvarchar](255) NULL,

    [Car Color] [nvarchar](255) NULL,

    [VON] [nvarchar](255) NULL,

    [VIN Number] [nvarchar](255) NULL,

    [Last Company Inventory] [nvarchar](255) NULL,

    [Car Model Description] [nvarchar](255) NULL,

    [District] [float] NULL,

    [SO Number] [nvarchar](255) NULL,

    [SO Date] [datetime] NULL,

    [S#O# Customer] [nvarchar](255) NULL,

    [AR Target] [nvarchar](255) NULL,

    [VAN Priority] [nvarchar](255) NULL,

    [Model Year] [float] NULL,

    [Car Line] [nvarchar](255) NULL,

    [Car Tag] [nvarchar](255) NULL,

    [Ship Number] [nvarchar](255) NULL,

    [Rail Number] [nvarchar](255) NULL,

    [Load Number] [nvarchar](255) NULL,

    [Ship Away Lane] [nvarchar](255) NULL,

    [Key Number] [nvarchar](255) NULL,

    [Transmission] [nvarchar](255) NULL,

    [Body Type] [nvarchar](255) NULL,

    [Engine Number] [nvarchar](255) NULL,

    [Car Spec] [nvarchar](255) NULL,

    [Stop Sale] [bit] NOT NULL,

    [Out Of Region] [bit] NOT NULL,

    [Ship To Dealer] [nvarchar](255) NULL,

    [Location] [nvarchar](255) NULL,

    [Case Number] [nvarchar](255) NULL,

    [Demo Reg#] [datetime] NULL,

    [Mix Id] [nvarchar](255) NULL,

    [Final Assembly Point] [nvarchar](255) NULL,

    [Mileage] [float] NULL,

    [Trans# Org#] [nvarchar](255) NULL,

    [Engine Org#] [nvarchar](255) NULL,

    [Rail Shipped] [datetime] NULL,

    [Truck Shipped] [datetime] NULL,

    [Port] [nvarchar](255) NULL,

    [Release Priority] [bit] NOT NULL,

    [Released To DAI] [datetime] NULL,

    [Paid SOA Date] [datetime] NULL,

    [DAI Scheduled] [datetime] NULL,

    [MNR Print Date] [datetime] NULL,

    [Pick Up Rail Date] [datetime] NULL,

    [Receipt Date] [datetime] NULL,

    [Receiving Driver #] [nvarchar](255) NULL,

    [Origin] [nvarchar](255) NULL,

    [Inventory Location] [nvarchar](255) NULL,

    [Parts Throw] [datetime] NULL,

    [Ship Away Lane Date] [datetime] NULL,

    [Pickup Date] [datetime] NULL,

    [Delivery Date] [datetime] NULL,

    [Subj To Inspection] [nvarchar](255) NULL,

    [DATs Import] [datetime] NULL,

    [61B Import] [datetime] NULL,

    [62B Import] [datetime] NULL,

    [Price Frozen Date] [datetime] NULL,

    [Invoiced] [nvarchar](255) NULL,

    [Shipping Zone] [nvarchar](255) NULL,

    [Accessory Complete] [datetime] NULL,

    [PDI Complete] [datetime] NULL,

    [UID] [nchar](25) NULL

    ) ON [PRIMARY]

    GO

    Table 3

    USE [Inbounds]

    GO

    /****** Object: Table [dbo].[Released] Script Date: 10/18/2013 8:44:44 AM ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Released](

    [VIN Key] [nvarchar](255) NULL,

    [VAN] [nvarchar](255) NULL,

    [Status] [nvarchar](255) NULL,

    [Car Model] [nvarchar](255) NULL,

    [Car Color] [nvarchar](255) NULL,

    [VON] [nvarchar](255) NULL,

    [VIN Number] [nvarchar](255) NULL,

    [Last Company Inventory] [nvarchar](255) NULL,

    [Car Model Description] [nvarchar](255) NULL,

    [District] [nvarchar](255) NULL,

    [SO Number] [nvarchar](255) NULL,

    [SO Date] [datetime] NULL,

    [S#O# Customer] [nvarchar](255) NULL,

    [AR Target] [nvarchar](255) NULL,

    [VAN Priority] [float] NULL,

    [Model Year] [float] NULL,

    [Car Line] [nvarchar](255) NULL,

    [Car Tag] [nvarchar](255) NULL,

    [Ship Number] [nvarchar](255) NULL,

    [Rail Number] [nvarchar](255) NULL,

    [Load Number] [nvarchar](255) NULL,

    [Ship Away Lane] [nvarchar](255) NULL,

    [Key Number] [nvarchar](255) NULL,

    [Transmission] [nvarchar](255) NULL,

    [Body Type] [nvarchar](255) NULL,

    [Engine Number] [nvarchar](255) NULL,

    [Car Spec] [nvarchar](255) NULL,

    [Stop Sale] [bit] NOT NULL,

    [Out Of Region] [bit] NOT NULL,

    [Ship To Dealer] [nvarchar](255) NULL,

    [Location] [nvarchar](255) NULL,

    [Case Number] [nvarchar](255) NULL,

    [Demo Reg#] [datetime] NULL,

    [Mix Id] [nvarchar](255) NULL,

    [Final Assembly Point] [nvarchar](255) NULL,

    [Mileage] [float] NULL,

    [Trans# Org#] [nvarchar](255) NULL,

    [Engine Org#] [nvarchar](255) NULL,

    [Rail Shipped] [datetime] NULL,

    [Truck Shipped] [datetime] NULL,

    [Port] [nvarchar](255) NULL,

    [Release Priority] [bit] NOT NULL,

    [Released To DAI] [datetime] NULL,

    [Paid SOA Date] [datetime] NULL,

    [DAI Scheduled] [datetime] NULL,

    [MNR Print Date] [datetime] NULL,

    [Pick Up Rail Date] [datetime] NULL,

    [Receipt Date] [datetime] NULL,

    [Receiving Driver #] [nvarchar](255) NULL,

    [Origin] [nvarchar](255) NULL,

    [Inventory Location] [nvarchar](255) NULL,

    [Parts Throw] [datetime] NULL,

    [Ship Away Lane Date] [datetime] NULL,

    [Pickup Date] [datetime] NULL,

    [Delivery Date] [datetime] NULL,

    [Subj To Inspection] [nvarchar](255) NULL,

    [DATs Import] [datetime] NULL,

    [61B Import] [datetime] NULL,

    [62B Import] [datetime] NULL,

    [Price Frozen Date] [datetime] NULL,

    [Invoiced] [nvarchar](255) NULL,

    [Shipping Zone] [nvarchar](255) NULL,

    [Accessory Complete] [datetime] NULL,

    [PDI Complete] [datetime] NULL,

    [UID] [nchar](25) NULL

    ) ON [PRIMARY]

    GO

  • Even Better I took data from all 3 and dumped them into one table. Now I need to Crosstab as such:

    Dealer District Carline Confirmed Released Dlr Inventory

    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

  • arosenbaum (10/18/2013)


    Even Better I took data from all 3 and dumped them into one table. Now I need to Crosstab as such:

    Dealer District Carline Confirmed Released Dlr Inventory

    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

    So if I understand you correctly you figured out how to get all your data in this table and you just need to crosstab from this table? Can you provide a dozen or so rows of sample data as inserts and provide an example of the results of your query should look like?

    _______________________________________________________________

    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/

  • arosenbaum,

    People are willing to help you, but we don't know your environment, your data, or anything. In order to make it easy for us to help, provide the DDL for tables and some sample data as insert statements.

    This isn't consulting. We aren't here to do your job on your schedule. We volunteer time as we can to assist.

Viewing 12 posts - 1 through 11 (of 11 total)

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