Skip to content
Advertisement

Search function stored procedure with multiple fields not returning expected results

I have a simple table with 4 rows as follows:

When I run the following query the results are exactly as expected: Query

Results

BUT I created a stored procedure as follows:

and execute it like this

I get these results

Am I going crazy here? I’ve already spent way too much time on this. Is there something I’m doing wrong? I might end up using dynamic SQL instead but I need to know what I’m doing wrong here.

Advertisement

Answer

You MUST at all times specify an explicit length for any CHAR, NCHAR, VARCHAR, NVARCHAR parameters! Otherwise they default to 1 character length!

Use this:

and your stored procedure will work just fine

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement