11-07-2010 06:09 PM
Hi,
I am trying to extract a set of data in a CSV file base on a condition (the file has a header in the first row). What is the best way of doing that? i thought I would use the database module and do a sql query on the CSV file. How would I do that? I only know how to do a SQL query on a database but not on a SQL file. Thanks!
Yik
11-07-2010 07:19 PM
There is an odbc driver for csv files but I think it would be simpler to just use the Read From Spreadsheet function to read from a csv file. Read the first line, compare it to whatever, then read the remainder if your condition is met. The top row is returned as an array so it's just basic array manipulation and comparisons. If you really want to use SQL, you could try writing a database query and treat the row values as column names.
11-07-2010 07:21 PM
I want to try the SQL approach with my CSV file, can you give a little more detail? Thanks!
11-07-2010 07:45 PM
What kind of extra detail do you want? "SELECT x FROM tablename WHERE column = y" is the general syntax. Try it. You are the one with the csv file.
11-07-2010 07:52 PM
Thinking a bit more about it, if you want data in the rows, the above query could work. If you want to base your query on the column name (i.e. header info), you will get an error if the exact column name does not exist. This might work as well if you do the correct error handling.
11-07-2010 09:20 PM
With the routine included in the database module, I just don't know where to supply the csv file location, since the routines are usually expecting an udl file. I have attached the file. For example, let say that the file is located at c:\
11-07-2010 10:07 PM
I believe you will have to use the Microsoft ODBC Data Source Administrator to define a DSN but beyond that, I really don't know. Question for Microsoft more than LabVIEW.
11-08-2010 10:01 AM
You are right. Thanks!