【发布时间】:2015-07-14 09:29:09
【问题描述】:
正在进行一个需要简单存储过程的大学项目:
创建一个存储过程,该过程采用一个接受日期的参数。日期的数据类型将是日期时间。此存储过程应返回该日期发生的所有房客和房产信息。
它将在大学时在 SQL Server 上提交,但目前我正在家里使用 MS Access 2010 进行培训。
表 = Property_For_Rent:
Pno \\( this is the property ID )
Address_1
Address_2
Address_3
表 = Renter
Rno \\( this is the renter ID )
Fname
Lname
表 = Viewing
Rno
Pno
Date
研究发现这里的另一个人有类似的难题(更容易调整,如果有人能指出哪里出了问题,那就太好了,谢谢!
create procedure sp_orders_by_dates
@startdate smalldatetime,
@enddate smalldatetime
as
select
OrderID,
o.CustomerID,
c.CompanyName as CustomerCompany,
s.ShipperID,
s.CompanyName as ShipperCompany,
ShippedDate
from
Orders o
join
Customers c on o.CustomerID = c.CustomerID
join
Shippers s on s.ShipperID = o.ShipperID
where
@startdate = ShippedDate,
@enddate = ShippedDate
order by
ShippedDate
【问题讨论】:
-
欢迎来到 SO。 +1 实际上承认它是一个大学项目,并展示你到目前为止所拥有的东西。
-
那么,问题到底是什么?
-
下载并安装 sql server express edition。不要用access来学习sql server。
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本不使用前缀! -
所以应该是
WHERE ShippedDate = @StartDate OR ShippedDate = @EndDate....
标签: sql sql-server parameters procedure