我有这个问题,我需要为我的存储过程设置“可选”参数工作正常。 例如,我有这样的:现在可以选择的sql参数
CREATE PROCEDURE [dbo].[Search]
(
@StartTime datetime = NULL,
@EndTime datetime = NULL,
@CustomerEmail nvarchar(255) = NULL,
@OrderStatusID int
)
,在我的.NET网站,我有这等的例子,请记住,只能有一个参数或有可能是所有的人:
commAdvanced.Parameters.Add("@StartTime", SqlDbType.DateTime).Value = startDate;
commAdvanced.Parameters.Add("@EndTime", SqlDbType.DateTime).Value = endDate;
commAdvanced.Parameters.Add("@CustomerEmail", SqlDbType.nvarchar).Value = null;
commAdvanced.Parameters.Add("@OrderStatusID", SqlDbType.Int).Value = null;
这是查询:
SELECT * FROM Order
WHERE CreatedOn > CAST(@StartTime as datetime)
AND CreatedOn < CAST(@EndTime as datetime)
AND Order.OrderStatusID = @OrderStatusID
AND Order.CustomerEmail = @PaymentStatusID
我越来越没有记录,当我这样做,有人可以帮我做什么,我需要改变。
哪里'@ PaymentStatusID'来自于你的'SELECT'声明? – Oded 2010-10-28 18:58:55