我正在更新一些旧的SQL代码,并在将* =运算符更新为Left Outer Join时出错

时间:2015-03-19 23:13:55

标签: sql-server outer-join legacy-code

我收到错误:

  

MSG 4145:在预期条件的上下文中指定的非布尔类型的表达式,靠近' Left'

思想?

USE [DatabaseName]
GO
/****** Object:  StoredProcedure [dbo].[spFilePlanNavigate]    Script Date: 03/19/2015 14:54:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER Procedure [dbo].[spFilePlanNavigate](@CategoryId int) 
As 
Set NoCount On
Begin
    If @CategoryId > 0
        Select FilePlan.*, Retention.Retention_Type, Retention.Retn_Description1 
            From FilePlan, Retention 
            Where FilePlan.Retention_Code Left Outer Join Retention.Retention_Code 
                And FilePlan.Category_Id = @CategoryId
    Else
        Select FilePlan.*, Retention.Retention_Type, Retention.Retn_Description1 
            From FilePlan, Retention 
            Where FilePlan.Retention_Code Left Outer Join Retention.Retention_Code 
                And FilePlan.Category_Id_Parent = @CategoryId
End

1 个答案:

答案 0 :(得分:0)

左外连接具有以下语法:

select cola, colb from table1 left outer join table2 
on table1.id = table2.id 
where table.catid = @catid

您的sql语句缺少' on' ' on'子句告诉SQL Server匹配列出的匹配列的行。