Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DO CASE equavalent in Transact-SQL
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01326640
Message ID:
01326675
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>Is there a DO CASE equavalent in Transact-SQL for procedural code, e.g.
>>>
>>>CASE @PersonType = ' '
>>>   One select statement
>>>case ...
>>>   Different select statement
>>>
>>>etc.
>>>
>>>Thanks in advance.
>>>
>>>Creating different strings and using sp_executesql doesn't sound like a good approach to me. I'm guessing I need to use IF statements since there seems to be no CASE alternative for procedural code in T-SQL.
>>
>>No. T-SQL CASE is used in a select statement to conditionally evaluate field results.
>>
>>IF..ELSE is ugly but it does work.
>
>Yes, I see that I don't have other choice except for creating multiple SPs for each type. I'm wondering which way would be better. From code maintenance point of view one procedure is definitely better.

What's wrong with one SP. You always can use structure like this:
IF @Something1
   BEGIN
   -- Select 1
   END
ELSE IF @Something2
   BEGIN
   -- Select 2
   END
ELSE IF @Something3
   BEGIN
   -- Select 3
   END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform