From: Petr Danes on
I have some text that I need to concatenate, but with a delimiter. Three
strings, A, B, C, where A and C are complicated expressions and B is a
space-dash-space.

I want the separator only if BOTH A and C are non-empty, otherwise only A or
C (or nothing, if they're both empty). I've been playing with IsNull and
NullIf functions, trying to influence the concatenation, but haven't come up
with anything useful. Doesn't T-SQL have a function that is the opposite of
Split?

Pete


--
This e-mail address is fake, to keep spammers and their address harvesters
out of my hair. If you want to get in touch personally, I am 'pdanes' and I
use yahoo mail. But please use the newsgroup when possible, so that all may
benefit from the exchange of ideas.


From: Uri Dimant on
Petr
Can you post sample data + expected result? BTW what version are you using?


"Petr Danes" <skruspammers(a)no.spam> wrote in message
news:u5Occcr5KHA.5848(a)TK2MSFTNGP06.phx.gbl...
>I have some text that I need to concatenate, but with a delimiter. Three
>strings, A, B, C, where A and C are complicated expressions and B is a
>space-dash-space.
>
> I want the separator only if BOTH A and C are non-empty, otherwise only A
> or C (or nothing, if they're both empty). I've been playing with IsNull
> and NullIf functions, trying to influence the concatenation, but haven't
> come up with anything useful. Doesn't T-SQL have a function that is the
> opposite of Split?
>
> Pete
>
>
> --
> This e-mail address is fake, to keep spammers and their address harvesters
> out of my hair. If you want to get in touch personally, I am 'pdanes' and
> I use yahoo mail. But please use the newsgroup when possible, so that all
> may benefit from the exchange of ideas.
>
>


From: Erland Sommarskog on
Petr Danes (skruspammers(a)no.spam) writes:
> Thank you Erland, CTEs and your CASE / COALESCE are what I needed. This
> is a bit different from Access SQL, which is the majority of my
> background, but I'm having a great time learning it.

The good news is that (almost) all I showed you is ANSI SQL, so the it
should work on Oracle, DB2, MySQL etc as well.

--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx