Posts

Showing posts from January, 2010

chomping isql and date conversion

Today a colleague was working on retrieving data from a Windows SQL Server database from within linux. He needed a bash script that would execute a query against the database and dump the results in comma delimited format. The SQL query he wrote was rather long and so was broken up into new lines and indented to ease editing and readability. This, however, caused a snag in isql. isql is a commandline tool that ships with linux ODBC that can be used to connect to an ODBC DSN and execute sql commands as well as execute batch files in unattended mode. isql parses batch files ( essentially SQL scripts ) in such a way as that each line is treated as a single command. It does not recognise the GO statement or any other command terminator. Our workaround was to chomp the script prior to piping it into isql. So here we go: Here is an example script. #--- mySqlScript.sql --- SELECT TOP 100 * FROM myTable t WHERE t.created_at between '2009-01-01' and '2009-12-31'