Others have already pointed out the missing quotes around the string criteria (= Adam, instead of = 'Adam').
I use a different technique to build the SQL to call, by constructing a template and replacing "parameters":
declare @s_QueryTemplate =
'
Select ROW_NUMBER() OVER (ORDER BY <<ORDER BY COLUMN NAMES>>) AS ##RowNum, <<COLUMN NAMES>>
INTO ##Results
From TableA
Where FirstName = ''<<SEARCH VALUE>>''
ORDER BY FirstName
'
SET @s_query =
REPLACE(
REPLACE(
REPLACE(
@s_QueryTemplate
, '<<ORDER BY COLUMN NAMES>>', @ColNames
), '<<COLUMN NAMES>>', @ColNames
), '<<SEARCH VALUE>>', @Search
)
I find this makes it much easier to see the structure of the code you're trying to create, including things like where there should be quotes.
@ColName = '''FirstName','LastName'''? If that's not the prob please paste the full sql and dump of @s_query.