C#
StringBuilder sb = new StringBuilder();
m_ContactList.ToList().ForEach(c => sb.Append(c.FirstName + "; "));
m_FirstNameDecription = sb.ToString();
SQL
--1
Select top 10 FirstName from Contact Where SexID =1
--2
select top 1 a from Contact cross apply (
select top 10 convert( nvarchar(100) , c.FirstName) + ', '
from Contact c
where c.SexID =1
for xml path ('')
) e (a)
Wynik z SQLa
--1 FirstName --------------------------------------------------------------------------- Václav Lubomír Viktor Karel Vlastimil Aleš Milan Vilém František Roman (10 row(s) affected) --2 a --------------------------------------------------------------------------- Václav, Lubomír, Viktor, Karel, Vlastimil, Aleš, Milan, Vilém, František, Roman, (1 row(s) affected)
2 komentarze:
Zawsze będzie ten jeden niepotrzebny znak po ostatnim elemencie.
E tam, zawsze można wykonać na budowanym stringu TrimEnd(';').
Prześlij komentarz