【发布时间】:2016-06-11 01:53:39
【问题描述】:
这是我的存储过程:
CREATE PROC [SPmainReport]
@startDate date = null,
@endDate date = null,
@customerName varchar = null,
AS
SELECT Distinct
VI.Code as CustomerCode, VI.Name as CustomerName, VI.Area as CustomerArea, VI.[Address] as [address], CP.ProductName as ProductName, CP.ProductQuantity as Quantity
from
VendorTrading VT inner join CustomerProducts CP on VT.Id = CP.VendorTradingId inner join VendorInfo VI on VT.VendorId = VI.Id
where
(VT.Tradedate between isnull(@startDate,VT.Tradedate) and isnull(@endDate,VT.Tradedate))
and VI.Name = ISNULL(@customerName, VI.Name)
执行时它不返回任何值,但如果我执行此查询:
SELECT Distinct
VI.Code as CustomerCode, VI.Name as CustomerName, VI.Area as CustomerArea, VI.[Address] as [address], CP.ProductName as ProductName, CP.ProductQuantity as Quantity
from
VendorTrading VT inner join CustomerProducts CP on VT.Id = CP.VendorTradingId inner join VendorInfo VI on VT.VendorId = VI.Id
where
(VT.Tradedate between isnull(@startDate,VT.Tradedate) and isnull(@endDate,VT.Tradedate))
and VI.Name = ISNULL('John', VI.Name)
它返回完全需要的数据。我完全困惑为什么会这样。完全没有区别。我确保脚本在同一个数据库上运行,并且它还包含完美的数据。这里是SP执行脚本:
USE [E:\SANDWICH3\ABC\BIN\DEBUG\DATABASE\ABC.MDF]
GO
DECLARE @return_value Int
EXEC @return_value = [dbo].[SPmainReport]
@startDate = '2015-12-25',
@endDate = '2015-12-25',
@customerName = N'John'
SELECT @return_value as 'Return Value'
GO
我注意到的一个更奇怪的事情是,如果我只用日期而不是名称来修改这个 SP 和限制条件。那么它工作正常。 我正在开发 SQL Server 的 Visual Studio 2013 接口。不是管理工作室(以防万一)
【问题讨论】:
-
sqlblog.com/blogs/aaron_bertrand/archive/2009/10/09/…(总是为变量类型分配长度)和blogs.sqlsentry.com/aaronbertrand/bad-habits-attachdbfilename(为什么你的数据库命名为
E:\SANDWICH3\ABC\BIN\DEBUG\DATABASE\ABC.MDF而不是ABC?) -
Name 仍然是 ABC,rest 是目标路径。正如我提到的,我正在使用 Visual Studio 界面
标签: sql sql-server visual-studio stored-procedures