I need to execute query and convert result to text. I know how to do it within Management S开发者_如何学Ctudio. But I need to do it within stored procedure and saved output result to text column
The query itself has no idea what a grid or text pane is - these are presentation niceties coded into Management Studio. If you want to combine the values in a row and concatenate them into a single string, then insert those rows into your text column (I hope you mean VARCHAR(MAX) or NVARCHAR(MAX), since TEXT is deprecated and shouldn't be used), you can say something like this, keeping in mind that you'll need to manually convert any non-string types (int, date, etc.) to varchar or nvarchar.
INSERT dbo.OtherTable(NVARCHAR_MAX_COLUMN)
SELECT varchar_column + CONVERT(VARCHAR(12), int_column) + ...
FROM dbo.table;
If you need to combine rows as well and insert one big value that represents a text dump of the whole table, then you can do it slightly differently:
DECLARE @v NVARCHAR(MAX) = N'';
SELECT @v += CHAR(13) + CHAR(10)
+ varchar_column + CONVERT(VARCHAR(12), int_column) + ...
FROM dbo.table;
INSERT dbo.OtherTable(NVARCHAR_MAX_COLUMN) SELECT @v;
加载中,请稍侯......
精彩评论