The following code works fine, but I can't find a way to make the other side of the equation dynamic as well so that I can handle both character field searches and integer field searches with the same stored procedure.
CREATE PROCEDURE [dbo].[TEST_SelectSearch]
@searchfor char(10),
@searchitem char(10)
AS
SET NOCOUNT ON
SELECT *
FROM [dbo].[patient]
where
CASE @searchfor
when 'Last Name' then lastname
when 'ID' then id
end
= '@searchitem'
The = '@searchitem' only works for the character field search & I need:
= @searchitem for the integer field search. I tried using another case statement for this part, but no luck. Would it be simplest to use one sp for the chars and one for the ints?
Anyone know how to do this?
TIA