0

我刚刚在一个UserBasics名为 name的表中创建了一个属性SkillType

我正在尝试SkillType在我的存储过程中使用(新值):

CREATE PROCEDURE SelectMentor 
    -- Add the parameters for the stored procedure here
    @Zip varchar(20) = NULL,
    @Company varchar(200) = NULL,
    @Designation varchar(100) = NULL,
    @Interest varchar(200) = NULL,
    @CurrentID varchar(200) = NULL,
    @SkillType varchar(50)  =NULL
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT 
       user_Id, user_Fullname,
       Designation, Company,user_Email
    FROM
       (SELECT
           user_Id, user_Fullname, user_Zip ,user_Need,user_Email,
           STUFF(
               (SELECT ', ' + Designation
                FROM   UserProfession
                WHERE  Prof_ID = a.user_Id
                FOR XML PATH (''))
                , 1, 1, '')  AS Designation,
           STUFF(
               (SELECT DISTINCT ', ' + Company
                FROM   UserProfession
                WHERE  Prof_ID = a.user_Id
                FOR XML PATH (''))
                , 1, 1, '')  AS Company
        FROM UserBasics AS a
        GROUP BY 
             user_Id, user_Fullname, user_Zip, user_Need, user_Email) s
   WHERE  
      (@Zip is null or user_Zip like '%'+@Zip+'%') and
      (@Interest is null or user_Need like '%'+@Interest+'%') and
      (@Company is null or Company like '%'+@Company+'%') and
      (user_Id != @CurrentID) and
      (SkillType = @SkillType) and
      (@Designation is null or Designation like '%'+@Designation+'%')
END
GO

但它说

消息 207,级别 16,状态 1,过程 SelectMentor,第 46 行
无效的列名称“SkillType”。

我知道它的缓存问题,但是我如何刷新 SQL Server 2005 中的缓存。

请指导我正确的方向

问候,

编辑

我还尝试刷新对象资源管理器并尝试重新启动服务,但仍然出现错误。我可以看到表格中的列。重新创建存储过程也没有让我走向成功

4

1 回答 1

2

您需要将新列 , 包含SkillType在子选择的选择列表中:

FROM
    (
      SELECT
           user_Id, user_Fullname, user_Zip ,user_Need,user_Email, 
           SkillType   -- <-----
           STUFF(
               (SELECT ', ' + Designation
                FROM   UserProfession
                WHERE  Prof_ID = a.user_Id
                FOR XML PATH (''))
                , 1, 1, '')  AS Designation,
           STUFF(
               (SELECT DISTINCT ', ' + Company
                FROM   UserProfession
                WHERE  Prof_ID = a.user_Id
                FOR XML PATH (''))
                , 1, 1, '')  AS Company
      FROM UserBasics AS a
      GROUP BY user_Id, user_Fullname, user_Zip ,user_Need,user_Email, 
               SkillType  -- <-----
    ) s

否则,您不能在外部WHERE子句中引用它。

于 2013-04-20T09:34:03.683 回答