我想将
XML Path的输出存储在变量中.但是这不起作用:
Declare @Tab dbo.SingleColumnTable Insert INTO @Tab Values( 'Jack' ) Insert INTO @Tab Values( 'Armageddon' ) Declare @RetVal varchar(8000) = '' Select Top 1 @RetVal = Data From ( Select ';' + ' ' + Name as 'Data' From @Tab t2 for xml path('') ) v
解决方法
尝试改变
Select Top 1 @RetVal = Data From ( Select ';' + ' ' + Name as 'Data' From @Tab t2 for xml path('') ) v
至
Select @RetVal = ( Select ';' + ' ' + Name as Data From @Tab t2 for xml path('') )