Sproc not Working with WildCard
Hello Everyone and thanks for your help in advance. I am writing a sproc for a SQL Server 2000 databse and am running into problems. The sproc is effectively a dictionary search looking for wildcard matches. When I write the SQL statement in Query Analyzer, it works fine:
SELECT * FROM tblDiagnosis
WHERE (Diagnosis LIKE '%')
returns all records. However the sproc:
CREATE PROCEDURE [sp_Search]
(@Diagnosis [char](100))
AS
SELECT * From tblDiagnosis
WHERE
([Diagnosis] Like @Diagnosis)
ORDER BY [Diagnosis]
GO
Fails to return any records. However, when I replace the @Diagnosis with '%', it returns all records. Obviously, I want to pass the Diagnosis parameter dynamically so I can perform searches, however, I really don't know why this isn't working. Any help on this issue will be greatly appreciated. Thanks.
|