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?

Recommended Answers

All 2 Replies

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.