You can use osql.exe to execute a query and store the results in a file.
Eg
osql -E -dTempDB -h-1 -w100 -n -i "C:\SQL_BagOTricks\ExportXML.sql" -o "C:\SQL_BagOTricks\ExportXML.XML"
OR
osql -E -dTempDB -h-1 -w100 -n -Q "SELECT CustomerID FROM Customer" -o "C:\SQL_BagOTricks\ExportXML.XML"
David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com