--like ....% 表示以....开头
-- %.... 表示以....结尾

--left (a,b); 最左边开始,返回b个长度字符串

WHERE 1=1
AND ( @DepartmentId IS NULL OR DepartmentId IN ( SELECT id FROM mdDepartment WHERE OrganID LIKE @DepartmentId+'%' ) )

 

写法2

select * from table where name like '%'+@name+'%'

posted on 2020-12-28 17:48  该吃药了  阅读(526)  评论(0编辑  收藏  举报