1

I need:

SELECT 
    @SQLString5 = 
        COALESCE(@SQLString5 + ' ', '')
        + CASE(IF FIRST THEN ' FROM ' ELSE ' full OUTER JOIN ')
        + 'VV' + ZZZ.ZZ
    FROM ZZZ

e.g. I'm building string by all nodes, and rule of building first node string part should be different, FIRST here is pseudocode.

is it possible?

Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
cnd
  • 32,616
  • 62
  • 183
  • 313
  • Use `XML PATH`. This approach to string concatenation is [not guaranteed to work](http://stackoverflow.com/questions/15138593/nvarchar-concatenation-index-nvarcharmax-inexplicable-behavior/15163136#15163136) – Martin Smith Oct 14 '13 at 13:33

1 Answers1

1

You can do this with row_number, but I think more neat is to use isnull(or coalesce, but for 2 values it's better to use isnull) for this, here's my little trick:

select
    @SQLString5 = 
    isnull(@SQLString5 + ' full outer join ' , ' from ') + 'VV' + @SOMEVALUE
from ZZZ

Actually don't know why do you adding @SOMEVALUE variable instead of data from ZZZ table

Roman Pekar
  • 107,110
  • 28
  • 195
  • 197