apr 9 blog

SQL query with output in XML format

I’m using the sql script below to Query SQL and get the output in XML in a generic way – it’s also possible to include the schema in XSD format by uncomment line 10. Script is just a sample based on data from a datafile from Fakename Generator, modify it for your data source:


SELECT TOP 10
		(SELECT TOP 1
			*
		FROM
			FakeNameGenerator AS SUB
		WHERE
			SUB.Number = MAIN.Number
		FOR XML RAW
			('Contact'), root('Contacts'), ELEMENTS XSINIL
			--, XMLSCHEMA //Enable to get the XSD schaema
		) AS XML
		FROM
			FakeNameGenerator AS MAIN
	ORDER BY
	MAIN.Number
Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+