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

How to fetch value of a column corresponding to a row fetched from qlikview by using SQL statement?

Hello Everyone,

I am new to QlikView . I am developing something in which I have to find the value of column from the first row retrived by the query in QlikView.

Actually I am creating a Database link, and then accessing it's table using SQL statement.

This Is what I am typing.

table1 :

SQL SELECT SHOP_SITE as fetch_site,wdays##1 ,wdays##2 ,wdays##3 ,
wdays##4 ,wdays##5 ,wdays##6 ,wdays##7
FROM SHOP_CALENDAR ;

Now I want to access the 'wdays##1'cloumn's  value corresponding to first record generated by this query.

For this I am trying let command with a peek value.

let day1 = peek('wdays##1',0,cycledate_table);

Thanks in advance !!!!!!

1 Solution

Accepted Solutions
Not applicable
Author

Hey guys I actually find out the solution.

Actually every thing was fine just a bit modificationwas required.

table1 :

SQL SELECT SHOP_SITE as fetch_site,wdays##1 ,wdays##2 ,wdays##3 ,
wdays##4 ,wdays##5 ,wdays##6 ,wdays##7
FROM SHOP_CALENDAR ;

and then to fetch the record

Let day1 = peek('WDAYS##1',0,'table1');

This is because irrespective of in which case you give the column name, it will always return the result of column which is in upper case.

Thanks guys for your help !!!

View solution in original post

9 Replies
kaushiknsolanki
Partner Ambassador/MVP

Hi,

   Bit modification required to your statement. i.e

   Let day1 = peek('wdays##1',0,'table1')

   Here the table name is not the actual table from which you got the data, it is the name given in qlikview. So in this case its table1.

  Hope this will help you.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable
Author

Thanks Kaushik for the reply.

I have incorporated the change as per as your suggestion.

But still the valus of day1 field is being shown as

day1 <NULL>  on the bottom right corner of the window debugger window.

Do you think it's ok?

Acutally I have to use this fields value to do some further calculation in my code.

Miguel_Angel_Baeyens

Hi,

Kaushik's suggestion is right, and it's possible that your first record doesn't have a value for field wdays##1. If you want the first value regardless null or empty values, try instead

LET vDay1 = FieldValue('wdays##1', 1);

Hope that helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

Not applicable
Author

Hi,

I have tried both your option . But still it's showing the value of day1 as null.

I have checked the value in setting --> variable columns also.

But there too it's value is shown null.

Can you suggest me how to check what value the variable day1 is containing ?

My SQL query is generating a table having more than 200 records and all are having wdays##1 columns value.

Miguel_Angel_Baeyens

Hi,

Both an inputbox or a textbox using that variable should show what the variable has. The Settings menu, Variable Overview will help to get that value as well. Check the attached application to see how that works.

Hope that helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

Not applicable
Author

Hey guys I actually find out the solution.

Actually every thing was fine just a bit modificationwas required.

table1 :

SQL SELECT SHOP_SITE as fetch_site,wdays##1 ,wdays##2 ,wdays##3 ,
wdays##4 ,wdays##5 ,wdays##6 ,wdays##7
FROM SHOP_CALENDAR ;

and then to fetch the record

Let day1 = peek('WDAYS##1',0,'table1');

This is because irrespective of in which case you give the column name, it will always return the result of column which is in upper case.

Thanks guys for your help !!!

Miguel_Angel_Baeyens

Hello,

amriteshraj wrote:

This is because irrespective of in which case you give the column name, it will always return the result of column which is in upper case.

Actually, this is not correct, and thanks for bringing it to our attention so further users can get the right thing. It's a very common mistake in the early stages of using QlikView, and it keeps happening to me once in a while.

When you retrieve data from a database, you are always using a driver external from QlikView, either a ODBC or an OLE DB (with the exception of the SAP or SalesForce Connectors developed by QlikView and certified by their corresponding vendors). These drivers have different settings and depending on the vendor, even for the same data base engine, these settings may vary.

In this case, the SQL statement you are using allows you to use lowercase field names even when they are actually uppercase in the database. Some other drivers (or some settings in the driver) may throw a "field not found" error when doing the SELECT. QlikView is case sensitive for both field names and values.

Regardless the SQL sentence, the field names loaded into the QlikView Document are always, by default, the same as they are returned by the database. So if the fields are all uppercase in the source, the will be loaded uppercase.

My mistake in this thread was not recommending you to specify a LOAD along with your SELECT (as I attached in my application, although I was using INLINE instead). But I do it now: do ALWAYS a LOAD for every table you are loading into QlikView. It's not required by the syntax but this will save development time and will help you debug this kind of errors, besides allowing you, of course, to rename, use functions, create new fields and so. Whether you specify the LOAD or not, QlikView will do it anyway.

So properly written, your script should look like this:

Table1:

LOAD fetch_site, // this one is likely lowercase because you manually renamed it in the SQL statement

     WDAYS##1,

     WDAYS##2,

     WDAYS##3,

     WDAYS##4,

     WDAYS##5,

     WDAYS##6,

     WDAYS##7;

SQL SELECT SHOP_SITE as fetch_site, wdays##1, wdays##2, wdays##3, wdays##4, wdays##5, wdays##6, wdays##7

FROM SHOP_CALENDAR;

If you

LOAD wdays##1 // lowercase

instead of

LOAD WDAYS##1 // UPPERCASE

You get an error (field not found), because the field name is not properly written.

Any further reference to this field, thus, must be done uppercase since it's the field actually loaded into QlikView (you will see that using the Table Viewer or CTRL + T). And your query analyzer will likely show likewise the field name uppercase. According to your script, it is interpreted by QlikView as follows:

table1:

LOAD *; // This line is what QlikView is doing

SQL SELECT SHOP_SITE as fetch_site,wdays##1 ,wdays##2 ,wdays##3 ,
wdays##4 ,wdays##5 ,wdays##6 ,wdays##7
FROM SHOP_CALENDAR;

The table above will be put into memory all field names in the same case than in the source database, because you haven't done any renaming.

So it's not that this is because it's irrespective of the case, but because the field name is actually uppercase, and in QlikView, field names and values are case sensitive.

It's very important to get it clear, to avoid errors in further developments and prevent further confusions.

Hope that makes sense and helps.

Miguel Angel Baeyens

BI Consultant

Comex Grupo Ibérica

Not applicable
Author

Thanks Miguel for apprising me with such valuable information.

Actually I am new to QlikView and unaware to such intricate details.

I will definitely keep your points in mind during future development.

Thanks a lot !!!!!!

montubhardwaj
Specialist

Hi Miguel,

That was awsome piece of information..... neva knew this.... Thx a ton