多条件组合查询,sql语句连接

多个条件组合查询,如果某个条件为空,则舍弃该条件

select @RCount=COUNT(*)  FROM t_user t LEFT JOIN  dbo.t_UserYearScore y
ON t.UserId=y.UserId INNER JOIN dbo.t_Organization o ON t.OrgNo=o.OrgNo
WHERE t.Name LIKE '%'+ isnull(@Name,'')+'%' AND t.OrgNo LIKE '%'+ isnull(@OrgNo,'')+'%' 
AND t.IdNumber LIKE '%'+ isnull(@IdNumber,'')+'%'

sql 语句连接

@sqlstr=@sqlstr+' where t.IdNumber like %'+@IdNumber+'%'

你可能感兴趣的:(sqlserver)