开发者

SQL Server: put select result in variable

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


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.


I think you need to cast all columns as nvarchar with concatinating it.


Just concatenate the fields you want (or all of them) into a varchar(max) or similiar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜