SQL stored procedure to produce custom XML text
0
votes
1
answer
228
views
I have around 30 tables from which I need to generate a specific XML format, which is consistent through the tables.
With my current solution I have a stored procedure for each 30 tables where I do:
select ''
+ ''
+ ''
+ ''
+ ''
+ ''
+ ''
+
from dbo.table
where the parantheses values are hardcoded for each table. So for example in one table (id column) is CUSTOMER_ID. While in a different table (id column) is STORE_ID. and (fieldname) is for example CUSTOMER_NAME. So they are all hardcoded column names in the brackets and primary key in .
So my stored procedure with all 30 tables is around 1000 lines long, as every column and primary key is hardcoded for each table.
I'm certain there is a dynamic way to achieve this functionality where columns/rows are somehow iterated over, but I can't figure it out.
Asked by Anton
(101 rep)
Jan 21, 2020, 01:15 PM
Last activity: Jun 11, 2025, 06:04 PM
Last activity: Jun 11, 2025, 06:04 PM