Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

c_neumann
New Contributor II

Condition for Where Statement - Between Dates

Hi Guys

Need a script for the following:

Need to pull all data in Table 2 where Date A (in Table 1) is between Start and End Date in Table 2.

Joining on Key

Any assistance will be appreciated:

Table1:
LOAD [Employee],
     [Key],
     [Record Number],
     [Date A],
[Status]                                                            

FROM
[..\.qvd]
(
qvd)

;

Table2:
LOAD [Key],
[Structure Entity],
[Start Date],
[End date],
Region,
Division,
     Plant
FROM
[..\QVData\.qvd]
(
qvd)

Where ([Date A] >= [Start Date] and  [Date A] <= [End date])

;

Tags (1)
1 Solution

Accepted Solutions

Re: Condition for Where Statement - Between Dates

Try:

Table 1

join

Table 2

then

Load *

Resident  Table1

where...

drop table table1;

Feeling Qlikngry?

How To /Missing Manual(25 articles)

7 Replies

Re: Condition for Where Statement - Between Dates

Try:

Table 1

join

Table 2

then

Load *

Resident  Table1

where...

drop table table1;

Feeling Qlikngry?

How To /Missing Manual(25 articles)

Re: Condition for Where Statement - Between Dates

How about this:

Table1:
LOAD [Employee],
    [Key],
    [Record Number],
    [Date A],
    [Status]

FROM [..\.qvd] (qvd);

Table2:

Left Keep (Table1)

LOAD *,

     Date([Start Date] + IterNo() - 1) as [Date A]

While [Start Date] + IterNo() - 1 <= [End Date];

LOAD [Key],
     [Structure Entity],
     [Start Date],
     [End date],
     Region,
     Division,
    Plant
FROM [..\QVData\.qvd] (qvd);

Not applicable

Re: Condition for Where Statement - Between Dates

try this...adapt if i am not undestand...


Table2:
LOAD [Key],
[Structure Entity],
[Start Date],
[End date],
Region,
Division,
     Plant
FROM
[..\QVData\.qvd]
(
qvd);


Filter:

load max([End date]) as max_date, min([End date]) as min_date resident Table2;


let max_dt=fieldvalue(max_date,1);

let min_dt=fieldvalue(min_date ,1);

drop table Filter;

inner join (Table2)

//Table1:
LOAD [Employee],
     [Key],
     [Record Number],
     [Date A],
[Status]                                                           

FROM
[..\.qvd]
(
qvd) where [Date A] >= min_dt and [Date A] <=max_dt;



c_neumann
New Contributor II

Re: Condition for Where Statement - Between Dates

Hi Sunny

The statement looks right, but now Table2 had 330 000 rows.

Will it load 330 000 x 330 000?

Is there not a more elegant solution?

I only want one record for Table2 where DateA from Table 1 is between Start Date and End date in Table2.

All other records in table2 can be disregarded.

c_neumann
New Contributor II

Re: Condition for Where Statement - Between Dates

Won't work, need a each row in table2 where DateA from Table 1 is between Start Date and End date in Table2.

Can't use a max date. Needs to look at Start and End Date for each record in Table2 and compare with Date A in Table1

Re: Condition for Where Statement - Between Dates

Look at my solution.

You are joining two tables and then taking what you need.

c_neumann
New Contributor II

Re: Condition for Where Statement - Between Dates

Hi Robert

I actually did look at this solution this afternoon and it's brilliantly simple!

I love solutions that are simple and achieve the goal in as little transformation as possible.

Thank you

Community Browser