Home Forums SQL Server 2008 T-SQL (SS2K8) query to get the name of a product with only incremental values in the quantity column RE: query to get the name of a product with only incremental values in the quantity column

  • This looks like homework or an interview question so ill post some usable data. Can you show what you have tried so far?

    CREATE TABLE tmpProduct (

    Product VARCHAR(32),

    [Year] INT,

    QTY INT,

    CONSTRAINT PK_tmpProduct PRIMARY KEY (Product, [Year])

    )

    INSERT INTO tmpProduct (Product, [Year], QTY)

    SELECT * FROM (VALUES

    ('Computer',2009,100),

    ('Computer',2010,200),

    ('Computer',2011,300),

    ('Computer',2012,400),

    ('printer', 2009,100),

    ('printer', 2010, 200),

    ('printer', 2011,250),

    ('printer', 2012,250),

    ('flash drive',2009,400),

    ('flash drive',2010,500),

    ('flash drive',2011,700),

    ('flash drive',2012,900),

    ('monitor', 2009,200),

    ('monitor', 2010,300),

    ('monitor', 2011,250),

    ('monitor', 2012,400),

    ('keyboard', 2009,100),

    ('keyboard', 2010,150),

    ('keyboard', 2011,200),

    ('keyboard', 2012,150))X(Product, [Year], QTY)


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]