简体   繁体   中英

Transaction table stored procedure

I have a transaction table (Id,UserId,FirstName,LastName,Products,Amount,CreatedDate)

I want to write a procedure say 'summarizeAmountByLastName' that accepts parameters @LastName,@Startdate,@EndDate,@MinimumSummedAmount and returns appropriate data from transaction table.

I'm new to writing stored proc like this. Things I tried is

SELECT UserId,FirstName,LastName,Products,SUM(Amount) as SummedAmount,
CreatedDate
from TestTable 
where CreatedDate between @StartDate and @EndDate 
group by UserId,FirstName,LastName,Products,Amount,CreatedDate 

Any suggestions would be appreciated.

you might need to play with it a bit, but likely you are looking for something like this for the query for your stored proc. refer to link posted by @Hamlet for syntax for creating stored proc.

SELECT UserId,FirstName,LastName,Products,SUM(Amount) as SummedAmount,
CreatedDate
from TestTable 
where 
    CreatedDate between @StartDate and @EndDate 
    and LastName = @LastName
group by UserId,FirstName,LastName,Products,Amount,CreatedDate
having  SUM(Amount) > @MinTotal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM