【问题标题】:Transaction table stored procedure事务表存储过程
【发布时间】:2015-03-24 10:30:09
【问题描述】:

我有一个交易表(Id,UserId,FirstName,LastName,Products,Amount,CreatedDate)

我想编写一个程序,比如“summarizeAmountByLastName”,它接受参数@LastName、@Startdate、@EndDate、@MinimumSummedAmount 并从事务表中返回适当的数据。

我是这样编写存储过程的新手。我尝试过的是

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 

任何建议将不胜感激。

【问题讨论】:

  • 你写的很可能是参数化查询。要编写存储过程,请参阅this 文档。
  • 您的程序目标不清楚,您能再解释一下。比如@MinimumSummedAmount输入参数有什么用

标签: sql sql-server sql-server-2008 stored-procedures transactions


【解决方案1】:

您可能需要稍微尝试一下,但您可能正在寻找类似的东西来查询您的存储过程。有关创建存储过程的语法,请参阅 @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

【讨论】:

    猜你喜欢
    • 2011-09-09
    • 1970-01-01
    • 2012-09-26
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多