• raghuldrag (12/30/2013)


    here i can such example

    create table estr

    (

    custo int,

    product varchar(20),

    val int,

    billed_date datetime

    )

    insert into estr(custo,product,billed_date,value) values('10','Milk','2013-04-11','2000')

    insert into estr(custo,product,billed_date,value) values('10','Milk','2013-04-21','500')

    insert into estr(custo,product,billed_date,value) values('10','Milk','2013-05-05','100')

    insert into estr(custo,product,billed_date,value) values('10','Milk','2013-05-11','2000')

    insert into estr(custo,product,billed_date,value) values('10','fruits','2013-05-11','500')

    insert into estr(custo,product,billed_date,value) values('30','fruits','2013-04-11','2000')

    insert into estr(custo,product,billed_date,value) values('30','fruits','2013-05-11','1000')

    My expecting output

    custo product value no.of.mon(bil_months)

    10 milk 4600 2

    10 fruits 500 1

    30 fruits 3000 2

    above example custo=10 milk has billed various date of april,may but when i count the month ll show only 2

    how to do that?

    Did you run my code?

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden