Is the field "DB_Name" spelled correctly or does it come from the database in table "DBs" all uppercase? Note that QlikView is case sensitive also for the names of the fields, so although the name may be uppercase in the SQL statement, it may be returned in lowercase (for example).
Apart from that, set a TRACE after DB_Name just to check its value:
LET DB_Name = Peek('DB_Name', $(i), 'DBs'); TRACE $(DB_Name);
Hope that helps.
Thank you, Miguel. Correct me if I'm wrong but
TRACE $(DB_Name)will only let me to refer to the value and I need to refer to the column name
$(DB_Name)to exclude given values. With
TRACE $(DB_Name)I get: ABC NOT IN ('ABC') but I need to get DB_Name NOT IN ('ABC').
PS Don't bother upper/lower cases - I've carelessly translated it into English, script is ok.
So if I understand it right, you are getting the expected value (table name) although you want to exclude some values from there. If my assumption is correct, do a WHERE in the SELECT DB_Name line to exclude as many table names as you want, so the FOR loop only take valid values.
Hope that helps.
To clarify: I first create a table of databases to query from and then do a loop on this databases to get Dim_1 values out of Table_1 in each databes. However, when doing the loop I don't want one table from the DBs to be queried in the loop.
DBs: table of databases to be queried, total number - 5
Data: table of Dim_1 values from Table_1 from 4 databases in DBs, one database is to be excluded.
Hopefully, now it'll be clear :-)
Adding to what Miguel suggested...
Are you using SQL Server as your database engine? If yes, then you need to use following naming convention :
-- Here the two dots (..) represent default schema for the login
So you need use something like this..
SELECT DB_Name FROM Configuration;
LET NoOfDBs = NoOfRows('DBs');
FOR i = 0 to $(NoOfDBs)-1
LET DB_Name = Peek('DB_Name', $(i), 'DBs');
'$(DB_Name)' AS DB_Name,
FROM $(DB_Name).dbo.Table_1 WHERE $(DB_Name) NOT IN ('DB_1');
Hope this helps!
The problem here is that the WHERE clause in the SELECT statement is not valid. This where clause is being passed to the database, and WHERE referencing a <tablename> is not syntax that the database server will understand. Where clauses filter on fields, not tables.
If you want to selectively open table, you will need to wrap the SELECT statement with a Qlikview If statement.
If '$(DB_Name)' <> 'DB_1' Then
SQL SELECT .....
Hope that helps