0

It is should be no problem to find but after long hours at my job I cannot notice what I'm doing wrong here.

There is very simple stored procedure:

ALTER PROCEDURE MyProc  
@input char(10)

AS

    BEGIN
        SET NOCOUNT ON;
        SELECT isonum 
        FROM iso where isonum LIKE '%' + @input + '%'
        ORDER BY isonum
    END

when executing a query: select isonum from iso where isonum like '%2333%' - I get the data,but when executing the stored procedure:

exec MyProc '2333' - I get nothing???

What's wrong here?

eugene.it
  • 417
  • 3
  • 13
  • 32
  • Does it work with an @input of varchar(10)? Is it padding your variable so that it's searching for `LIKE '%2333 %'`? – Danny Apr 08 '14 at 22:53

2 Answers2

2

Change to @input char(10) to @input varchar(10)

your sp is currently running

isonum from iso where isonum like '%2333 %'

Nick.Mc
  • 18,304
  • 6
  • 61
  • 91
0
ALTER PROCEDURE MyProc  
@input varchar(10)   --<-- Use varchar here 

AS

    BEGIN
        SET NOCOUNT ON;
        SELECT isonum 
        FROM iso where isonum LIKE '%' + @input + '%'
        ORDER BY isonum
    END

'CHAR' or 'NCHAR' fixed data types and they add white spaces to the passed strings if it is less then the maximum length of the data.

M.Ali
  • 67,945
  • 13
  • 101
  • 127