Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Export table in to txt Expand / Collapse
Author
Message
Posted Monday, May 13, 2013 9:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, June 13, 2014 1:19 AM
Points: 4, 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
Post #1452185
Posted Monday, May 13, 2013 12:33 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 2:34 PM
Points: 12,923, Visits: 12,342
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 Moden's 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)
Post #1452269
Posted Monday, May 13, 2013 5:13 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, June 13, 2014 1:19 AM
Points: 4, Visits: 5
Thank you Sean Lange,

This is routine work and will be running every hours, thanks
Post #1452362
Posted Tuesday, May 14, 2013 4:41 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 20, 2013 11:38 PM
Points: 92, 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
Post #1452492
Posted Tuesday, May 14, 2013 11:35 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, June 13, 2014 1:19 AM
Points: 4, 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
Post #1452924
Posted Wednesday, May 15, 2013 1:17 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, June 20, 2013 11:38 PM
Points: 92, 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 :)
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
Post #1452952
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse