I am trying to export some data from one of my SQL Server database. It has a little over 300 tables and I didn't see any way to export this data using the SSMS wizard as it only does one table at a time. I need to use the delimiter "/". So I have been playing around with xp_cmdshell and it seems to do almost everything I need it to do except one thing.
I need it to just output the table name like this: table1.txt where right now it outputs as [dbo].[table1].txt
Execute sp_MSforeachtable 'Execute master.dbo.xp_cmdshell ''sqlcmd -S SERVER\INSTANCE -E -d DB -q "SET NOCOUNT ON SELECT * FROM ?"''' -W -h-1 -o C:\DBA\?.txt -s "/"'''
Here is one trick to do it
You need to add the above logic in your code.
Note : If your table name has
[dbo].[
or]
characters in it then this could mess up