September 2003 Blog Posts
About a month ago I was asked by a contractor I work with who needed to import some very plain, fixed-width, ASCII text file data into SQL Server. In fact, this SQL Team post is very much like his situation, in that he also was going to convert PLAIN, FIXED-WIDTH, ASCII TEXT (did I mention that already?) into XML and THEN import it into SQL Server. I was absolutely floored that someone would even CONSIDER doing it this way. The only analogy I can think of is taking a haiku that perfectly expresses an idea, and then spend months or...
As Damian pointed out, you can do a lot of cool things with DOS command-line functions. Lately I'm particularly enamored of the for command.
The DOS for command works like a for...next loop in Basic, C/C++/C#, Java(Script) etc., only you can have it traverse a filespec (like dir *.txt would), a directory tree, or even the contents of a file. To modify Damian's example a little, you could actually execute each individual SQL script with the following:
for %a in (*.sql) do osql -E -Sserver <%a
The %a is a DOS replaceable parameter, and it holds the complete file name of each file in the *.sql...
Figured no one would remember this blog next year during the presidential election... :)
So now our rampant SQL Team egos can rant unchecked by the need to remember we too were once SQL n00bs who didn't know anything! MWUH HAHAHAHAHAHAHAHA!!!!
I sense graz dreading the moment he gave me a blog here, and sympathize deeply.
My current blog title (TRUNCATE TABLE master..sysdatabases) may change in the future, unless overwhelmingly positive feedback or threats ask that it remain, so if you like it, let me know!
Thanks graz! Once again you've put another great thing on an otherwise dull Internet!