Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dually Dynamic where clause using the case statement
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Dually Dynamic where clause using the case statement
Divers
Thread ID:
00809111
Message ID:
00809111
Vues:
82
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform