Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello guys,

I'm having a table as Below.

Pmaster
PID Pname
1   SB
2   LA
3   Rd
4   FD


Tmaster(Table name)
with Column Name
PID,Txn TYpe,Txn Amount,Date of Transaction


NOTE-
TXN TYPE=transaction type(might be Sb,la etc)
Txn Amount=Transaction AMount

So my question is: i want list the product having the maximum montly, average number of transactions (consider the last 6 months of data) ?
Posted
Updated 9-Nov-14 0:58am
v2
Comments
Maciej Los 9-Nov-14 6:58am    
Not clear! Please, be more specific and provide more details...

1 solution

PLease, read my comment to the question. I'm not sure what you want, but my advice is to create stored procedure[^](SP) like this:
SQL
CREATE PROCEDURE GetAmountRangeDates
    @dateFrom DATETIME,
    @dateTo DATETIME
AS
BEGIN
    SELECT PM.PID, PM.Pname, TM.TYpe, SUM(TM.Amount) AS Amount
    FROM Pmaster AS PM LEFT JOIN Tmaster AS TM O PM.PID=TM.PID
    WHERE TM.[Date of Transaction] BETWEEN @dateFrom AND @dateTo
    GROUP BY  PM.PID, PM.Pname, TM.TYpe
END


Above SP gets 2 input parameters: @dateFrom and @dateTo. Use both to define date range.

How to use sp in code?
How to: Execute a Stored Procedure that Returns Rows[^]
How to call SQL Server stored procedures in ASP.NET by using Visual Basic .NET [^]
 
Share this answer
 
Comments
Manas Bhardwaj 9-Nov-14 13:16pm    
Yes +5!
Maciej Los 9-Nov-14 15:42pm    
Thank you, Manas ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900