J'ai une table SQL qui ressemble à ce qui suitSQL combiner des chaînes de colonnes
p1 c1 c2 c3 c4 c5 c6 c7
A B C D E F NULL NULL
A B C NULL NULL NULL NULL NULL
A B NULL NULL NULL NULL NULL NULL
A NULL NULL NULL NULL NULL NULL NULL
i besoin d'une requête SQL SELECT avec 1 colonne et la sortie pour ressembler
Result
A > B > C > D > E > F
A > B > C
A
i essayé imbriqué select cas cependant je reçois seulement NULLS
select
case when x.p1 IS not NULL then(
x.p1 + case when x.c1 IS not NULL then(
' > '+ x.c1 + case when x.c2 IS not NULL then(
' > '+ x.c2 + case when x.c3 IS not NULL then(
' > '+ x.c3 + case when x.c4 IS not NULL then(
' > '+ x.c4 + case when x.c5 IS not NULL then(
' > '+ x.c5 + case when x.c6 IS not NULL then(
' > '+ x.c6 + case when x.c7 IS not NULL then(
' > '+ x.c7)end)end)end)end)end )end)end) end as tree
from mytable
- Yat-il un meilleur moyen d'obtenir le résultat que je veux?
- Quel est le problème avec mon cas de sélection?
Et pour 2012 peut être raccourci à 'SELECT p1 + CONCAT (» > '+ c1,'> '+ c2,'> '+ c3,'> '+ c4,'> '+ c5,'> '+ c6,'> '+ c7) de mytable' [SQL Fiddle] (http : //www.sqlfiddle.com/#! 6/02b05/1) –
@MartinSmith Je pense que c'est tellement génial qu'il mérite une réponse de son propre chef. – GolfWolf
Ce n'est qu'un changement progressif à votre réponse et je suppose que le PO veut quelque chose qui fonctionnera en 2008 et en 2012 de toute façon. –