I've an SQL statment like this
declare @keyword varchar(100)='ndee'
select ISNUMERIC(@keyword)
select * from teststaken where (
(firstname like '%' + @keyword + '%') or
(lastname like '%' + @keyword + '%') or
TestTakerEmail like '%' + @keyword + '%' or
(ISNUMERIC(@keyword)=1 and TestsTakenID = @keyword)
)
Its only a searching query for selecting rows based on a keyword given against different columns. But the teststakenID column is integer. So it works fine if we avoid the last comparison when a string is given. If a string or a word is given it throws an error
Conversion failed when converting the varchar value 'andee' to data type int.
But what I tried to accomplish was checking the keyword is integer type or not and only integer type then compare with the teststakenid column. Please help me to find what I did wrong