0

即使数据库有匹配的记录,以下存储过程也不会返回任何内容。Rowcount是问题吗?有人请帮忙吗?

ALTER PROCEDURE [dbo].[Usp_get_product_rates]
  -- Add the parameters for the stored procedure here
  @pcat1 CHAR(3),
  @pcat2 CHAR(3),
  @pcat3 CHAR(1)
AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON

      SELECT b.pcat1,
             b.pcat2,
             pcat3,
             rate1,
             rate2
      FROM   Product_Rates AS a
             JOIN Master_Rates AS b
               ON a.pon = b.pon
      WHERE  b.pcat1 = @pcat1
             AND b.pcat2 = @pcat2
             AND pcat3 = 'P'

      IF @@RowCount = 0
        BEGIN
            SELECT b.npa,
                   b.nxx,
                   blockid,
                   Inter_state_rate,
                   Intra_state_rate
            FROM   Rates_STF2 AS a
                   JOIN TPM AS b
                     ON a.pon = b.pon
            WHERE  b.pcat1 = @pcat1
                   AND b.pcat2 = @pcat2
                   AND pcat3 = '@pcat3'
        END
  END 
4

2 回答 2

1

可能会改变这个

pcat3 = '@pcat3' 

对此

pcat3 = @pcat3 

在你的 where 子句中。

于 2012-08-27T20:07:45.107 回答
0

我认为你应该这样做:

If NOT Exists (select 1 from Product_Rates as a join Master_Rates as b on a.pon = b.pon where b.pcat1 = @pcat1 and b.pcat2 = @pcat2 and  pcat3 = 'P' )  
BEGIN
    select b.npa,b.nxx,blockid,Inter_state_rate,Intra_state_rate from Rates_STF2 as a join TPM
    as b on a.pon = b.pon  
    where b.pcat1 = @pcat1 and b.pcat2 = @pcat2 and  pcat3 = @pcat3
END 
于 2012-08-27T19:34:59.723 回答