Reputation: 3807
When i do for example:
select * from test
This will produce a result with all columns and rows of table test. It is possible to assign this result as "text" in one variable?
Thanks
Upvotes: 1
Views: 3082
Reputation: 452967
This does what you asked for
DECLARE @Result nvarchar(max)
DECLARE @Xml xml = (select * from master..spt_values FOR XML PATH)
SELECT @Result = CAST(@Xml.query('string(.)') as nvarchar(max))
PRINT @Result
I suspect that you probably want some column/row delimiters in there though.
I'm not sure whether this could be altered to do this. My XML skills are a bit lacking.
Upvotes: 1
Reputation: 3539
Just concatenate the fields you want (or all of them) into a varchar(max) or similiar.
Upvotes: 0
Reputation: 9668
I think you need to cast all columns as nvarchar with concatinating it.
Upvotes: 0