Luis Cazares (6/6/2013)
Sean Lange (6/6/2013)
Here is another:
select stuff(isnull(col1 + '/', '') + isnull(col2 + '/', ''), LEN(isnull(col1 + '/', '') + isnull(col2 + '/', '')), 1, '')
from Table_1
Sean, you gave me an idea.
select stuff(isnull('/' + col1, '') + isnull('/' + col2, ''), 1, 1, '')
from Table_1
No wonder my post count is so low lately. Between you, Sean, and some of the other heavy hitters, I don't have much to do anymore. Well done!
If you're guaranteed to have only 2 columns, a slight variation on the COALESCE approach would work. Haven't checked it for performance, but it might be a little faster because it only does 2 concatenations instead of 3.
SELECT COALESCE(Col1+'/'+Col2,Col1,Col2)
--Jeff Moden
Change is inevitable... Change for the better is not.