In a stored procedure I am using a where clause similar to the following :
Declare @pBar_Code varchar(51)
Set @pBar_Code=convert(varchar(51),UPPER(@Bar_Code))
Select barcode from XYZ
where UPPER(bar_code) like Concat('%',@pBar_Code,'%')
The @pBar_Code variable can be either text or numeric. The barcode column in table XYZ is varchar(51)
I receive the following error message, when setting @pBar_Code=512 or another number. The variable should allow numbers, text or both.
Msg 8114, Level 16, State 5, Line 8
Error converting data type varchar to numeric.
What do I need to do in order to utilize the Like operator to do a partial lookup for any rows that
Msg 8114, Level 16, State 5, Line 8
Error converting data type varchar to numeric.
Declare @x Table (Id int Identity(1,1), barcode varchar(51))
Insert into @x(barcode)
Values ('abc'),
('123'),
('544')