我刚刚在名为UserBasics
的表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
但它说
Msg 207,Level 16,State 1,Procedure SelectMentor,Line 46
列名称“SkillType”无效。
我知道它的Cache问题,但我如何在SQL Server 2005中刷新缓存。
请指导我正确指导
此致
修改
我还尝试刷新对象资源管理器并尝试重新启动服务,但仍然出现错误。我可以看到表格中的列。重新创建存储过程也没有让我走向成功
答案 0 :(得分: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
子句中引用它。