• ByronOne (9/17/2012)


    Hi Sean

    Thanks for getting back to me and I hope you'll be able to help.

    Ok, here is the DDL you were looking for:

    IF OBJECT_ID('TempDB..#MyTable') IS NOT NULL

    BEGIN

    DROP TABLE #MyTable

    END

    CREATE TABLE [dbo].[#MyTable]

    (

    [WeekEndDate] [date] NULL,

    [site] [varchar](5) NULL,

    [ItemDescription] [varchar](75) NULL,

    [PlanItemsSold] [int] NULL,

    [ActualItemsSold] [int] NULL

    )

    SET IDENTITY_INSERT #mytable ON

    --===== Insert the test data into the test table

    INSERT INTO #MyTable (WeekEndDate, [site], ItemDescription, PlanItemsSold, ActualItemsSold)

    SELECT 'Aug 12 2012 12:00AM', 'Central', 'Item1', '10', '7'

    UNION ALL SELECT 'Aug 12 2012 12:00AM', 'Central', 'Item2', '5', '3'

    UNION ALL SELECT 'Aug 12 2012 12:00AM', 'Central', 'Item3', '21', '7'

    UNION ALL SELECT 'Aug 12 2012 12:00AM', 'South', 'Item1', '14', '3'

    UNION ALL SELECT 'Aug 12 2012 12:00AM', 'West', 'Item2', '11', '7'

    UNION ALL SELECT 'Aug 19 2012 12:00AM', 'West', 'Item1', '17', '9'

    UNION ALL SELECT 'Aug 19 2012 12:00AM', 'North', 'Item1', '21', '32'

    UNION ALL SELECT 'Aug 19 2012 12:00AM', 'East', 'Item1', '13', '19'

    --===== Set the identity insert back to normal

    SET IDENTITY_INSERT #MyTable OFF

    So what is the desired output based on this sample data and maybe an explanation of how that should happen?

    _______________________________________________________________

    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/