declare @locationType varchar(50); declare @SearchTerm NVARCHAR(100); SELECT column1, column2 FROM whatever WHERE (@locationType = 'location' AND account_location LIKE @SearchTerm) OR (@locationType = 'area' AND Area LIKE @SearchTerm) OR (@locationType = 'division' AND xxx_location_division LIKE @SearchTerm)
Make sure @SearchTerm
starts with / end with %
→ or uses '%' + @SearchTerm + '%'
.
Additional information about LIKE operator .
--- Update ----
SELECT column1, column2 FROM whatever WHERE ( CASE @locationType WHEN 'location' THEN account_location WHEN 'area' THEN Area WHEN 'division' THEN xxx_location_division END ) LIKE @SearchTerm
source share