Hello! I'm new to MSSQL. We have 15 tables with a total number of columns 500 pieces. Tell me how to combine the results of XML into one document? UNION ALL does not help.
I added a table with the MSSQL server addresses and their IDs to the database. Therefore, it became necessary to exclude it from the results. Took request:
Select( SELECT 'TABLE1' as 'name' , --выводит в тэге XML имя таблицы ( SELECT * FROM 'TABLE1' --таблица 1 FOR XML RAW ('Columns') ,type ) --формат выгрузки данных FOR XML RAW, type --формат выгрузки данных SELECT 'TABLE2' as 'name' , ( SELECT * FROM 'TABLE2' FOR XML RAW ('Columns') ,type ) FOR XML RAW, type) But it cannot be combined with UNION. The point is to have column headers in the upload. And the results were written in one file.
Help me please.
For 2 days I could not win ... I would be grateful for any help and examples.
Before that I used:
SET NOCOUNT ON DECLARE @CMD varchar(max) = '' DECLARE @AllTablesXML table (XMLData XML) SELECT @CMD += ';SELECT '''+TABLE_NAME+''' as ''@name'' , ( SELECT * FROM ' + QUOTENAME(T.TABLE_SCHEMA) + '.' + QUOTENAME(T.TABLE_NAME) + 'FOR XML RAW (''Columns'') ,type ' + CHAR(10) + ' ) FOR XML RAW, type' FROM INFORMATION_SCHEMA.TABLES T --WHERE T.TABLE_NAME in ('your List of tables') Uncomment if you need to extract specific tables --SELECT @CMD --Exec (@CMD) INSERT INTO @AllTablesXML EXEC (@CMD) SELECT XMLData FROM @AllTablesXML FOR XML RAW 