Archive

How to read data from a CSV file and put into DB Connect’s query?

Hi,

I want to pull data from a CSV file and put that all data in a SQL query.
For e.g.-
In CSV:
'ABC','DEF','GHI','JKL','MNO'
SQL QUERY:
SELECT emp_name FROM emp WHERE emp_name IN ('ABC','DEF','GHI','JKL','MNO')

I want these “emp_name” get into my SQL query form CSV automatically.

Please help me on this.

Regards,
Ritesh Aggarwal

Tags (1)

Splunk Employee
Splunk Employee

try putting the database query command into a map command. I just messed around with this on DBX2, appears to work well:

state="WA" OR state="CA" | map search="|dbxquery query=\"SELECT%20*%20FROM%20%60northwind%60.%60employees%60%20WHERE%20Region%3D%22$state$%22\" connection=\"dbx-mysql\""

I used this page to url encode: http://meyerweb.com/eric/tools/dencoder/

Forgot to mention -- this will be wicked slow and may make your DBA angry because it's calling that sql command over and over again. If you're going to do this in production, you should just index or lookup your database table and then do the whole job in SPL.

0 Karma
State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!