【发布时间】:2009-06-25 14:46:18
【问题描述】:
这是我当前实现的存储过程,它返回给定订单 ID 的订单状态。有两种情况,
- 有匹配的订单ID,我将检索相关状态,
- 没有匹配的订单 ID(即不存在的订单 ID)。
我的困惑是,如何在一个存储过程中优雅/高效地实现这两个功能,以便我返回情况 1 的匹配订单 ID 并在情况 2 中指示客户端没有匹配的订单 ID?
我使用 VSTS 2008 + C# + ADO.Net + .Net 3.5 作为客户端,使用 SQL Server 2008 作为服务器。
CREATE PROCEDURE [dbo].[GetStatus]
@ID [nvarchar](256),
@Status [int] output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @Status = [Status]
FROM [dbo].[OrderStatus]
WHERE (@ID = [ID]);
END
提前致谢, 乔治
【问题讨论】:
标签: c# .net sql-server stored-procedures ado.net