Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 select lines of text file

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2008-06-18 : 13:06:38
hi

i have a text file with lots of data.
but i would like to select only lines containg key word such as *loc

and export those lines to new text file.

Can this be done in sql in any way?

thanks in advance

JeriHatTrick
Starting Member

11 Posts

Posted - 2008-06-19 : 11:32:41
I would use the bcp command line utility. You would first need to create a format file to control the import and export of the flat file.

BCP DB.schema.TempTable format -nul -T -f C:\BCP\MyFormatFile.fmt

-nul means use null as your username. You do this because -T tells bcp to use a trusted connection. The -f designates the command as a create format file command.

After this you can import your flat file to a designated table like so:

BCP DB.schema.TempTable IN C:\SomeDirectory\FlatFile.dat -T -f C:\BCP\MyFormatFile.fmt

and then export the result of a query out to another flat file

bcp "SELECT * FROM DB.schema.TempTable WHERE col1 LIKE '%loc'" queryout NewFlatFile.txt -c -T

I can't guarantee that the above syntax is exactly correct but you can find more information at this resource:
http://msdn.microsoft.com/en-us/library/ms162802.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-19 : 11:47:41
You could also use DTS Import Export wizard to export the data just use the select query as source and then give text file as destination.
Go to Top of Page
   

- Advertisement -