[英]Transaction table stored procedure
I have a transaction table (Id,UserId,FirstName,LastName,Products,Amount,CreatedDate) 我有一个交易表(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. 我想编写一个过程说“ summarizeAmountByLastName”,该过程接受参数@ LastName,@ Startdate,@ EndDate,@ MinimumSummedAmount并从事务表中返回适当的数据。
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. 有关创建存储过程的语法,请参阅@Hamlet发布的链接。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.