(untested)

SELECT YEAR(IssueDate),
SUM(CASE WHEN DATEDIFF(dd, issuedate, PaymentDate) BETWEEN 0 AND 13 THEN
Amount),
SUM(CASE WHEN DATEDIFF(dd, issuedate, PaymentDate) BETWEEN 14 AND 27
THEN Amount),
SUM(CASE WHEN DATEDIFF(dd, issuedate, PaymentDate) >=28 THEN Amount)
FROM Mytable
GROUP BY YEAR(IssueDate)

--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.


"Przemo" <p.dutkiewiczdeltatrans.pl> wrote in message
news:0caf01c3414a$79ca9210$a101280aphx.gbl...
> Hi,
>
> I have no idea how to write such a procedure.
> I have a table with columns:
>
> 1. IssueDate
> 2. PaymentDate
> 3. Amount
>
> I would like to get result with columns:
>
> 1. Year (of IssueDate) - grouping column
> 2. Amount1 (when PaymentDate is between 0 and 14 days
> after IssueDate)
> 3. Amount2 (when PaymentDate is between 14 and 28 days
> after IssueDate)
> 4. Amount3 (when PaymentDate is between 28 and -- days
> after IssueDate)
>
> It's impossible ;) - for me !
>
> Thanks
> Przemo