Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Performing an IF statement in a SQL Statement.
Message
 
À
25/02/2005 12:02:24
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Database:
MS SQL Server
Divers
Thread ID:
00990593
Message ID:
00990604
Vues:
12
>What I need to do is create a view that contains a name field. If the Full Name doesn't exists, I want to combine the rest of the fields to return a full name. If the last names are the same, I want to return JOHN AND SALLY SMITH. If the last names are not the same, I want to return PAYTON MANNING / MARVIN HARRISON.

Mike,

Perhaps something like this would work:
SELECT ISNULL(FullName, 
              Name1First + ' ' +
                 (CASE WHEN Name1Last=Name2Last THEN 
                            'AND ' + Name2First
                       ELSE Name1Last + ' / ' + Name2First + ' '
                  END) + Name2Last) AS NewFullName
Laterness,
Jon

P.S. I just realized this was in the .Net forum. My response was based on T-SQL syntax for SQL Server.
Jon Rosenbaum
Devcon Drummer
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform