Matching a smaller piece of text in a local variable to a larger piece of text that I have pulled in a query I think this is a simple question, but google searching for 30 minutes was mostly wasted time as all I can find is matching a variable to a 'randompieceoftext'. 

Anyways, suppose I have a local variable called @ServerName. This server name will be something like CCPWIQAUL. I need to match this server name to various path names, which is of the form:

serverName.something.somethingelse.com

These path names are pulled from a database, and will be in the column vManagedEntity.Path

How do I do something like this?

Is @ServerName is IN vManagedEntity.Path?
You can use the CHARINDEX() function to do this:

SELECT vManagedEntity.Path
FROM vManagedEntity.Path
WHERE CHARINDEX(@ServerName,Path) &gt; 0


Or, you can craft a LIKE query:

Assuming you want to do a Starts With match on the Path field:

SELECT vManagedEntity.Path
FROM vManagedEntity.Path
WHERE Path LIKE @ServerName + '%'


If you want to do an Ends With, change to:

SELECT vManagedEntity.Path
FROM vManagedEntity.Path
WHERE Path LIKE '%' + @ServerName


Or, a Contains:

SELECT vManagedEntity.Path
FROM vManagedEntity.Path
WHERE Path LIKE '%' + @ServerName + '%'