Write to a text file from MS SQL Server

There are several things you need to know to be able to do this.

  1. How to enable ad hoc queries.
    This guy enable-Ad-Hoc-Distributed-Queries shows you how.
  2. How to format the driver string and specify your directory and filename. Like this:
    OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')
  3. How to create a text file in the right format. This format works:
    "ColumnName1","ColumnName2"
    "value11", "value21"
    "value21", "value22"

There. That was only slightly unreasonably difficult. Now you can

[sourcecode language="sql"]Select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')[/sourcecode]
and
[sourcecode language="sql"]Insert into OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')
Values ('Col1', 'Col2')[/sourcecode]

Grep for Windows is FindStr

Grrr. Where's grep when you need it on a Windows box? No, you don't need cygwin. You just need:

[sourcecode language="powershell"]findstr /?[/sourcecode]

And yes it does regular expressions. For example:

[sourcecode language="powershell"]
Echo "Here Is A Sentence" | Findstr /i "\<Sen[a-zA-Z]*e\>"
TaskList /v | findstr /i "Where[']sGrep.exe"
[/sourcecode]

Restore files from an Apple Time Machine Backup to Windows

As noted in Reading a Mac OS X disk from Windows if you can plug your Mac OS X drive into your Windows computer then you can use HFS Explorer to read it.

This works fine for Apple Time Machine Backups: look for the directory called /Backups.backupdb/ and within that, the name of your computer. You'll find dated directories of your backups. If you're just after the most recent version of your files, then look for a directory called "Latest".

It's quite clever — the folder for a given date shows you not just files backed up on that date but everything that was on your original disk at that date. The magic of file system links.