--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+'%'