Help need for better query

  • CREATE TABLE TABLEA

    (

    purpose VARCHAR(10),

    contactTime datetime

    )

    INSERT INTO TABLEA

    SELECT 'Takecare',GETDATE()

    UNION ALL

    SELECT 'Takecare',GETDATE()

    UNION ALL

    SELECT 'Takecare',GETDATE()

    UNION ALL

    SELECT 'welcome',GETDATE()

    UNION ALL

    SELECT 'welcome',GETDATE()

    SELECT * FROM TABLEA

    Is there any way that In one query I can get below output?

    I want to know that for each purpose how many call been made for each week up to 12 week.

    I can do it using writing same code for 12 time with different date range but is any other way to get the same out put?

    Purpose week1 week2 week3........week12

  • Depending on your definition of "week1" and the like, a classic CrossTab should do it. Have a look at the related article referenced in my signature.

    If you need further explanation, please post ready to use sample data as described in the first article in my sig.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

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

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