比较SQL Server函数中的两个参数

时间:2014-07-12 12:06:23

标签: sql-server-2008

Create Function GetProducts (@AttributeValue NVARCHAR(max)) 
RETURNS NVARCHAR  
AS  
BEGIN  
    DECLARE @CountA INT  
    DECLARE @CountB INT  
    DECLARE @ProductValue NVARCHAR(max)

    SELECT @CountA = Count(*) 
    FROM CRM_fn_ac(@AttributeValue)

    SELECT @CountB = Count(*) 
    FROM product 
    WHERE filteredviewname = 'filteredciti_ac 
      AND attributename ='c_products' 
      AND value IN (SELECT * FROM CRM_fn_ac(@AttributeValue)

   IF @CountA =@CountB
   BEGIN
       SELECT @ProductValue= @AttributeValue
   END

   RETURN @ProductValue
END

我在IF条件附近收到错误。我想设置

productvalue = attributevalue when CountA = CountB

1 个答案:

答案 0 :(得分:0)

添加缺少的括号...

改变这个:

SELECT @CountB = Count() from product where filteredviewname='filteredciti_ac and attributename ='c_products' and value in (select * from CRM_fn_ac(@AttributeValue)

对此:

 SELECT @CountB = Count() from product where filteredviewname='filteredciti_ac' and attributename ='c_products' and value in (select * from CRM_fn_ac(@AttributeValue))

filteredviewname 列上过滤时,您也忘了关闭单引号...