Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dually Dynamic where clause using the case statement
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Dually Dynamic where clause using the case statement
Miscellaneous
Thread ID:
00809111
Message ID:
00809111
Views:
84
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
Next
Reply
Map
View

Click here to load this message in the networking platform