I know this is a simple question but here it goes. I’ve created a search button in Visual Studio using an SQL Statement. It works for first name and last name, but I also want it to search int such employee Id’s. Here is the code :
SELECT ID, fName, lName, Discription, Box
FROM tb1
WHERE (fName LIKE '%' + @fName + '%') OR (lName LIKE '%' + @lName + '%') OR (ID LIKE '%' + @ID + '%')
When I test it, I get the error :
"Conversion failed when converting the varchar value '%' to data type int.
You cannot use
LIKEwith integers, so you will have to convert theIDtovarchar.To convert you can use
CASTorCONVERT:http://msdn.microsoft.com/en-us/library/ms187928.aspx
Ex:
CAST(ID as varchar)Your query: