Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Script use Excel List to SQL resquest

Hello,

I don't if it's possible...

I have an Excel file like this :

     Num_Customer
     0123
     5156
     9656

     ...

1. I want load this file in my script  --> OK

(using : LOAD Num_Customer FROM [path:excel_file.xls] (biff, embedded labels, table is feuil1$);

2. Use it in SQL request like : --> KO

Name_TABLE : SELECT * FROM SQL_table_Name WHERE Customer IN ( MY_CUSTOMER_IN_EXCEL_LIST)

I know it's possible to use 'Entry field' (using : '0123', '5156','9656')


Somebody to help ?? Thanks.

1 Solution

Accepted Solutions
maxgro
MVP
MVP

for 100 customers you can try to build a Qlik variable and use it in SQL statement

// replace woth your excel file

excel:

load * inline [

Num_Customer

     0123

     5156

     9656

     100

     200

];

filter:

load

  chr(39) & concat(Num_Customer, chr(39) & ',' & chr(39)) & chr(39) as f

Resident excel;

let vfilter = Peek('f');

drop table filter;

now use the variable vfilter

Name_TABLE:

SQL

SELECT * FROM SQL_table_Name WHERE Customer IN ($(vfilter));

View solution in original post

11 Replies
krishna_2644
Specialist III
Specialist III

Sorry.

do you mean, you only want to load the values which exists in num_customer?

Not applicable
Author

Hi,

Yes,  tables in my datawehouse have more than 100.000.000 lines, and users want just see around 100 customers.

I don't want load all lines from my database... 
So, i have an excel file with customer (can change often)... and i want use this file to load only the good line.  

krishna_2644
Specialist III
Specialist III

oh got it. then try this:

CustomersFromExcel:

Load Disitinct

CustomerID,

OtherCustomerFieldList

from Customer.excel;

Data:

load *,CustID

from xyz

where exists(CustomerID,CustID);

drop table CustomersFromExcel;

Not applicable
Author

Sorry,

it seems not work, for information my database is on Sql Server

krishna_2644
Specialist III
Specialist III

that was a script format .

You have to edit that according your connections and tables.

if you have no idea,please post the table names and their fields.

Not applicable
Author

I have an error : impossible open file 'c:\........\my_table'  ...

Not applicable
Author

 

EXCEL_LIST :

LOAD TEXT(TOTO) as TOTO_1
FROM

(
biff, embedded labels, table is feuil1$);


DATA :
load * from dwh.dbo.my_table where exists(TOTO_1,TOTO_ID)

krishna_2644
Specialist III
Specialist III

try this way:

YourCustomerTable:

LOAD Num_Customer

FROM [path:excel_file.xls]

(biff, embedded labels, table is feuil1$;

Name_TABLE :

load *

where where exists(Num_Customer ,CustomerID);

SELECT *

FROM SQL_table_Name

WHERE Customer IN ( MY_CUSTOMER_IN_EXCEL_LIST); //this where  clause is not mandatory//


drop table YourCustomerTable;




Chage the field names as per you table field name.


Thanks

Not applicable
Author

Hi,

Thanks to your help.

I'm at home, i hope find time to try tomorrow...