Ms sql 2000 动态组合条件

      Select 
      A.ID, A.TypeName, A.Code,
      A.Content, A.BuildIn, A.ParentID, B.Content CategoryDisplayName,
      B.BuildIn CategoryBuildIn, B.RefTableName
      From Code A    
        left join Code B on(A.TypeName = B.Code and B.TypeName = #39CodeCa + tegoryName#39)
      where
       (
       (@TypeName is null) or (A.TypeName = @TypeName))
       and ((@Content is null ) or (A.Content = @Content))
       and ((@Code is null) or (A.Code = @Code))
       and ((@BuildIn is null) or (A.BuildIn = @BuildIn))
       and ((@ID is null) or (A.[ID] = @ID))
       and ((@CategoryBuildIn is null) or (B.BuildIn = @CategoryBuildI + n))
       and ((@ParentID is null) or (A.ParentID = @ParentID))
      )

 

这段代码能在SQL SERVER 2000 上跑

如果参数为空,那么对因的Where 条件不起作用

你可能感兴趣的:(JOIN,sql,sql,server,null)