I want to store the output of for XML Path in a variable. However this doesn't work:
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
As you can see I am trying to set the column name of returned output as Data but it doesn't work. I get error Invalid column name 'Data'.
Try changing
Select Top 1 @RetVal = Data
From
(
Select ';' + ' ' + Name as 'Data'
From @Tab t2
for xml path('')
) v
to
Select @RetVal =
(
Select ';' + ' ' + Name as Data
From @Tab t2
for xml path('')
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With