SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Export table in to txt


Export table in to txt

Author
Message
trisno
trisno
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 5
dear Gurus,

I want to export data in table to txt

SELECT [StatBeginTime]
,[MDASum]
,[BureauName]
,[MDA]
FROM [kpidb].[dbo].[t_MDA_1]

the result :
2013-05-13 00:14:00.000 290 bjm 261651
2013-05-13 00:29:00.000 226 bjm 203767
2013-05-13 00:44:00.000 174 bjm 15730

how to process so can create file txt in c:\\ directory ??? many thanks
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25902 Visits: 17518
trisno (5/13/2013)
dear Gurus,

I want to export data in table to txt

SELECT [StatBeginTime]
,[MDASum]
,[BureauName]
,[MDA]
FROM [kpidb].[dbo].[t_MDA_1]

the result :
2013-05-13 00:14:00.000 290 bjm 261651
2013-05-13 00:29:00.000 226 bjm 203767
2013-05-13 00:44:00.000 174 bjm 15730

how to process so can create file txt in c:\\ directory ??? many thanks


Is this a one time export or something you need to do routinely?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
trisno
trisno
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 5
Thank you Sean Lange,

This is routine work and will be running every hours, thanks
Bhavpreet Singh Narang
Bhavpreet Singh Narang
SSC Journeyman
SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)

Group: General Forum Members
Points: 98 Visits: 97
You can run a Sql Command in the scheduled job to do the desired task for you. Following is the syntax for the same.

SQLCMD -S YourSQLServer -d YourDatabase -U YourUserName -P YourPassword -Q “Your Query” -s “,” -o “C:\Yourfilename.csv"

Feel free to get back in case of any issues.

Regards,
Bhav
SSISDevelopers.wordpress.com
trisno
trisno
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 5
HI Bhavpreet Singh Narang,

I have try your command but there were error :
For My Server Name : 10.67.172.202
Database Name : morscdb
Table name for query : dbo.AO_MT
the error like below :


:\Documents and Settings\Administrator>SQLCMD -S 10.67.172.202 -d morscdb -U sa
-P sa -Q "Select* FROM dbo.AO_MT" -s "," -o "C:\Yourfilename.csv"
sqlcmd: 'FROM dbo.AO_MT"': Unexpected argument. Enter '-?' for help.


which one is wrong ? thank you
Bhavpreet Singh Narang
Bhavpreet Singh Narang
SSC Journeyman
SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)

Group: General Forum Members
Points: 98 Visits: 97
Hi,
I could replicate the issue you are facing the copying the template query and pasting it in command prompt after making the required changes.
Workaround: Just type the whole command in the command prompt and it will surely work Smile
I guess, there is some special character\Unicode conversion of space or something is causing an issue.. Not sure.. Let me know if you could find the exact culprit..
Regards
Bhav
ssisdevelopers.wordpress.com

Regards,
Bhav
SSISDevelopers.wordpress.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search