2 lanlanzhibi lanlanzhibi 于 2013.10.17 14:37 提问

关于设置参数值和直接拼接SQL语句问题

DECLARE @SysBranchSysNo int,@C1SysNo int,@RepeatNum INT
SET @SysBranchSysNo=1;
SET @C1SysNo=1073;
SET @RepeatNum=1
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY Quantity desc ) AS DATA_ROW_NUM, * FROM (
SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY SysNo,SysBranchSysNo ORDER BY totalNum) as RepeatNum,* FROM dbo.v_product) Product
WHERE SysBranchSysNo=@SysBranchSysNo
AND C1SysNo=@C1SysNo AND RepeatNum=@RepeatNum AND onlineqty>0 ) A) B WHERE DATA_ROW_NUM BETWEEN 181 AND 200;
为什这条语句执行结果是没数据,如果把WHERE SysBranchSysNo=@SysBranchSysNo改成WHERE SysBranchSysNo=1这样的执行结果就有值了。

1个回答

lanlanzhibi
lanlanzhibi   2013.10.17 16:11
已采纳

找到原因了,改成这样就行了
DECLARE @SysBranchSysNo int,@C1SysNo int,@RepeatNum INT
SET @SysBranchSysNo=1;
SET @C1SysNo=1073;
SET @RepeatNum=1
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY Quantity desc ) AS DATA_ROW_NUM, * FROM (
SELECT * FROM (SELECT ROW_NUMBER() OVER(PARTITION BY SysNo,SysBranchSysNo ORDER BY totalNum) as RepeatNum,* FROM dbo.v_product
WHERE SysBranchSysNo=@SysBranchSysNo
) Product
WHERE C1SysNo=@C1SysNo AND RepeatNum=@RepeatNum AND onlineqty>0 ) A) B WHERE DATA_ROW_NUM BETWEEN 181 AND 200;

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!