Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to write parameterized filter condition in query while fetching data

Hi,

I have a requirement where I need to pull data from a database and my filter condition should be parameterized and should come from a text/excel file. So that business user can open that text/excel file and can change the condition accordingly.

For example:

My query is:

Select *

from dbo.Customer

where customerID in (22, 12)

and StateID in (100, 102, 125)

Now in above query how can I store these customerID values & StateID values in text/excel and this query calls those parameters from that file and then execute. In a way it will be dynamic so tomorrow user can go to this file and change the parameter value and without chaning any code the script will still work.

Best Regards,

Sachin

1 Solution

Accepted Solutions
alexandros17
Partner - Champion III
Partner - Champion III

If your xls file has 2 rows and one column in wich you have:

Values

(22, 12)

(100, 102, 125)

you can

MyTable:

Load

     Values

From myFileXls;

Let row1=Peek('Values',1,'MyTable');

Let row2=Peek('Values',2,'MyTable');

then your select will be

Select *

from dbo.Customer

where customerID in $(row1)

and StateID in  $(row2)

hope it helps

View solution in original post

2 Replies
alexandros17
Partner - Champion III
Partner - Champion III

If your xls file has 2 rows and one column in wich you have:

Values

(22, 12)

(100, 102, 125)

you can

MyTable:

Load

     Values

From myFileXls;

Let row1=Peek('Values',1,'MyTable');

Let row2=Peek('Values',2,'MyTable');

then your select will be

Select *

from dbo.Customer

where customerID in $(row1)

and StateID in  $(row2)

hope it helps

Not applicable
Author

Thanks. It worked for me....