I'm new to MSSQL though I have some grounding in MySQL.

At the moment, I'm trying to use a variable. Reduced to simpler form, my query to search people with 'and' in their name is:

DECLARE @MyVar nchar;
SET @MyVar = '%and%';
SELECT name,email FROM db.dbo.users WHERE name LIKE @MyVar;

Can't get this query to work. I'm sure it's a pretty obvious syntax error to someone who knows TSQL.

Baby steps, but still falling on my posterior.

Any ideas?

Remove the semi-colons, and upgrade nchar to something more than one char.

Nice, thanks pritaeas. Once again, you save the day.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.