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;