-1

2つのテーブルを比較してから、一致するレコードがないレコードのみを除外する必要があります。次に、それらの行のいくつかだけを返す必要があります。私が使用する行を返すには...

SELECT  *
    FROM     (SELECT  ROW_NUMBER() OVER (ORDER BY Orderby ASC)
                 AS Row, * FROM vImportFiltered where userid <> @userID)
                AS vImport
    WHERE  Row >= @NumbFrom AND Row <= @NumbTo

私が使用するレコードのフィルターには...

SELECT * FROM ImportProducts IPここで、IP.ImpProdNameID=@impProdNameIDおよびIP.ImpProdCatID=@ImpProdCatIDおよび

  NOT EXISTS (SELECT *

           FROM   dbo.ProductDetails PD INNER JOIN
                      dbo.ProductsLU PL ON PD.LUProdSellUseID = PL.LUProdSellUseID
        WHERE
           IP.ImpProductID = PD.ProdImpID AND
           (CONVERT(varchar(36),PL.UserID) = @userID))

両方とも別々に機能しますが、それらを組み合わせようとするとエラーが発生します。

SELECT
    *
FROM
  (SELECT  ROW_NUMBER() OVER (ORDER BY Orderby ASC)
                 AS Row, * ImportProducts IP Where IP.ImpProdNameID = @impProdNameID and IP.ImpProdCatID = @ImpProdCatID 
and    
      NOT EXISTS (SELECT *

           FROM   dbo.ProductDetails PD INNER JOIN
                      dbo.ProductsLU PL ON PD.LUProdSellUseID = PL.LUProdSellUseID
        WHERE
           IP.ImpProductID = PD.ProdImpID AND
           (CONVERT(varchar(36),PL.UserID) = @userID)) as vImport
WHERE  Row >= @NumbFrom AND Row <= @NumbTo

エラー:

Msg 102, Level 15, State 1, Line 17 
Incorrect syntax near 'ImportProducts'. 
Msg 156, Level 15, State 1, Line 25 
Incorrect syntax near the keyword 'as'.

私も試しました

WHERE
           IP.ImpProductID = PD.ProdImpID AND
           (CONVERT(varchar(36),PL.UserID) = @userID))And Row >= @NumbFrom AND Row <= @NumbTo

私は何が間違っているのですか?

ありがとう

4

1 に答える 1

2

あなたは欠けていますFROM

SELECT *
FROM
  (SELECT  ROW_NUMBER() OVER (ORDER BY Orderby ASC) AS Row, * 
    FROM ImportProducts IP -- added your missing FROM
    Where IP.ImpProdNameID = @impProdNameID 
    and IP.ImpProdCatID = @ImpProdCatID 
    and    
      NOT EXISTS (SELECT *
                  FROM   dbo.ProductDetails PD 
                  INNER JOIN dbo.ProductsLU PL 
                    ON PD.LUProdSellUseID = PL.LUProdSellUseID
                  WHERE IP.ImpProductID = PD.ProdImpID 
                    AND (CONVERT(varchar(36),PL.UserID) = @userID)
                  )
  ) as vImport
WHERE  Row >= @NumbFrom 
    AND Row <= @NumbTo
于 2012-05-27T23:24:15.087 に答える