问题描述
- 关于设置参数值和直接拼接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这样的执行结果就有值了。
解决方案
找到原因了,改成这样就行了
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;
时间: 2024-10-31 19:28:24