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)
 how to parse a file (txt or html)

Author  Topic 

saglamtimur
Yak Posting Veteran

91 Posts

Posted - 2002-01-14 : 04:49:02
i need to know if it is possible (and how) to open a text (or html) file which is located on a local path and grab some lines, insert them to a table. (as i use filesystem obj with ASP to do this, but dont know if its possible with SQL server and t-Sql). thanks...

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-14 : 04:53:17
Hi

I guess it would be possible. You could use xp_cmdshell to read the text file. But T-SQL is not the right tool to use here. VB Script is much better. If you want it running in SQL Server you could run it as a DTS task. That gives you the flexability of VB Script / Filesystem object without running an ASP page.

Hope that helps

Damian
Go to Top of Page

saglamtimur
Yak Posting Veteran

91 Posts

Posted - 2002-01-14 : 10:00:25
ok thanks but, i dont know how to use xp_cmdshell proc, is it possible to open a text file with this proc (i think yes but dunno how) and take all its content and pass it to a string variable (this is my main problem)? later on i think its easy to parse this string by using substring.

Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-01-14 : 17:15:28
Hi

I wouldn't use xp_cmdshell actually, now I think more about it.
You can not declare a local text variable, so you would need a varchar (8000 chars max), and parsing it using substring will be horrible.

I would stick with vbscript.



Damian
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2002-01-14 : 19:18:07
If your data is delimited you could use BCP and pull it into a holding table, already parsed for you, that's if you don't want to use DTS. However, in this case, I'd say DTS is your best bet.

Mike
"A program is a device used to convert data into error messages."
Go to Top of Page

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2002-01-14 : 21:27:21
I'd go with DTS. I use it for heaps. However, you might have troubles if your filename is constantly changing - ie datestamped etc. However you could explain your problem further and we might be able to help.

What is the source of the text file anyway?

I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

saglamtimur
Yak Posting Veteran

91 Posts

Posted - 2002-01-15 : 08:27:23
thanks to all, i solve my problem with DTS.

Go to Top of Page
   

- Advertisement -