使用Set Sql Server,第一个查询不会返回任何内容

时间:2015-12-22 11:09:14

标签: sql-server tsql

很抱歉再一次现在我又得到了一个问题,第一个查询不会出现只有第二个查询正在运行并返回请帮助,就像我从第二个查询获得所有列而不是第一个查询中的任何内容

 WITH set1
    AS (SELECT
      BillCrtDtm,
      BillModDtm,
      Billing.BillingID,
      Billing.BillTotAmt,
    FROM dbo.Billing
    WHERE BillOrgGrpID = @IOrgID
    AND (BillModDtm BETWEEN @ILastUpdDtFrom AND @ILastUpdDtTo)  ORDER BY BillOrgID ASC, BillModDtm ASC OFFSET @ILastRecNum * @PAGE_SIZE ROWS
    FETCH NEXT @PAGE_SIZE ROWS ONLY)

   SELECT
      BICrtDtm,
      BIModDtm,
      BillItemID,
      BIItemPrice,
      BIItemName,
      BIItemBuyingPrice,
      BIInvStockMntc,
      BBInvManf
    FROM BillItem
    WHERE BIOrgGrpID = @IOrgID
    AND BIBillID IN (SELECT
      BillingID
    FROM set1)

1 个答案:

答案 0 :(得分:1)

哦,我得到了对不起..... FYI:列被编辑并且数量很少,以使其理解

我发布它以供将来帮助

WITH set1
AS (SELECT
  BillCrtDtm,
  BillModDtm,
  Billing.BillingID,
  Billing.BillTotAmt,
  BillIsInsPaid

FROM dbo.Billing
WHERE BillOrgGrpID = @IOrgID
AND (BillModDtm BETWEEN @ILastUpdDtFrom AND @ILastUpdDtTo)  ORDER BY BillOrgID ASC, BillModDtm ASC OFFSET @ILastRecNum * @PAGE_SIZE ROWS
FETCH NEXT @PAGE_SIZE ROWS ONLY)

SELECT
  BICrtDtm,
  BIModDtm,
  BillItemID,
  BIItemPrice,
  BIItemName,
  BIItemBuyingPrice,

  BIInvStockMntc,
  BBInvManf
FROM BillItem
WHERE BIOrgGrpID = @IOrgID
AND BIBillID IN (SELECT
  BillingID
FROM set1)
End