见鬼了,求救啊,我的SQL条件查询为什么出不来数据啊!!!!!
CREATE PROCEDURE O_TEST
@ReceiveName varchar(100),
@CreateBillDate varchar(20),
@PuctaseContractID int
AS
select * from O_Receive where
(@ReceiveName is null or ReceiveName like '% ' + @ReceiveName + '% ') and
(@CreateBillDate is null or CreateBillDate <= DATEADD(day, 1, @CreateBillDate) ) and
(@PuctaseContractID is null or PuctaseContractID = @PuctaseContractID)
如上,郁闷的很!
------解决方案--------------------1.
这个 SP 可以 Create 成功吗?
2.
修改版本:
DECLARE
@sql nvarchar(2000),
@Parms nvarchar(2000)
SET @Sql = 'select * from O_Receive where
(@ReceiveName is null or ReceiveName like ' '% ' + @ReceiveName + '% ' ') and
(@CreateBillDate is null or CreateBillDate <= DATEADD(day, 1, @CreateBillDate) ) and
(@PuctaseContractID is null or PuctaseContractID = @PuctaseContractID) '
SET @Parms = '@CreateBillDate varchar(20), @PuctaseContractID int '
sp_executeSql @Sql, @Parms, @CreateBillDate, @PuctaseContractID
3.
先将所有参数传入 NULL 测试是否有数据
Hope helpful!
------解决方案--------------------查询分析器
exec O_TEST @ReceiveName=‘’,
@CreateBillDate= ' ',
@PuctaseContractID=1
付几个参数试试
,如果没有问题,打开数据库跟踪,跟踪一下