AgentID, Address, RegNo, CnNo, IssueDt, SubmitDt, NoOfDays
Example of data is:
AgentID Address RegNo CnNo IssueDt SubmitDt NoOfDays
1 No 5, Jln Abc KL123 11111 4/12/03 4/15/03 3
1 No 5, Jln Abc KL123 12345 5/10/03 5/20/03 10
1 No 5, Jln Abc KL123 13000 6/13/03 6/13/03 0
1 No 5, Jln Abc KL123 15123 8/15/03 8/16/03 1
NoOfDays actually is DateDiff("d", IssueDt, SubmitDt)
I have to build a report for each Quarter that contains the following:
Agent: 1
Address: No 5, Jln Abc
RegNo: KL123
Total of CN: 3
Total of CN(with Days>0): 2
Days (Min): 3
Days (Max) : 10
This is based on the 2nd quarter (from April to June).
What I did is, I created 3 views.
1)A view that gets Count(CnNo) GROUP BY all the fields HAVING DatePart("quarter", IssueDt) = varQuarter
2)A view that gets Count(CnNo) GROUP BY all the fields HAVING DatePart("quarter", IssueDt) = varQuarter AND NoOfDays > 0
3)A view that gets Min(NoOfDays), Max(NoOfDays) GROUP BY .....HAVING DatePart("quarter", IssueDt) = varQuarter
Right now, I hard code the varQuarter as 2.
After creating all these views, I joined them together to become a view & put all the info in the crystal report to produce the report.
My problem is to make the report dynamic.
I don't know how to pass the Quarter variable into these views.Take the sql for each of the views, place them into a stored procedure, and do the appropriate joins. Replace all your hardcoded varQuarter with @.VarQuarter and define @.VarQuarter as an input parameter for the stored procedure.
Then call it like this:
EXEC BigReportQuery @.VarQuarter=3
The definition of BigReportQuery would start like this:
CREATE PROCEDURE [dbo].[BigReportQuery]
@.VarQuarter int
AS
SELECT x,y,z FROM SomeTable INNER JOIN ... HAVING DatePart("quarter",IssueDt)=@.VarQuarter ... etc.
GO
Alternatively, just combine calls to each of the existing views but from within the stored procedure.
No comments:
Post a Comment