Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

SQL where condition

Hello,

I'm running below script.

LOAD Distinct

Date(floor(LotStartDateTime),'YYYY-MM-DD hh:mm:ss.fff') as TempMaxDateTime,

Date(WeekEnd(LotStartDateTime),'DD-MM-YYYY') as WeekEndDate

Resident LatestWeek;

Let vWeekEndDate=Peek('WeekEndDate',-1);

Temp1:

LOAD Date(Max(TempMaxDateTime),'DD-MM-YYYY') as MaxDateTime

Resident Temp;

Let vMaxDate=Peek('MaxDateTime',-1);

LOAD *,

     LotStartDateTime AS TempLotStartDateTime

;

SQL SELECT *

FROM "Split Data".dbo."Week2"

Where

Day(LotStartDateTime) >= Day('$(vMaxDate)')

and

Day(LotStartDateTime) <= Day('$(vWeekEndDate)')

;

When i run the above query in qvw file, i'm getting the below error message as shown in second image.

In sql dates are like this

2011-06-08 00:10:12

2011-06-08 14:04:25

2011-06-09 11:00:04

Untitled1.png

Untitled2.png

13 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Change this part

SQL SELECT *

FROM "Split Data".dbo."Week2"

Where

Day(LotStartDateTime) >= Day('$(vMaxDate)')

and

Day(LotStartDateTime) <= Day('$(vWeekEndDate)')

;

to

SQL SELECT *

FROM "Split Data".dbo."Week2"

Where

Day(LotStartDateTime) >= Day($(=Date(vMaxDate,'MM/DD/YYYY')))

and

Day(LotStartDateTime) <= Day($(=Date(vWeekEndDate,'MM/DD/YYYY'))

;

Celambarasan

Not applicable
Author

If i change now i'm getting the error as

Untitled.png

Not applicable
Author

Sorry instead of Day i want to retrive the date only..

i'm poor in sql. please give a way to retrive the dates only

Not applicable
Author

I tried below code also but it is not working...

Let vWeekEndDate=Peek('WeekEndDate',-1);

Let vWeekEndDateDB=Date('$(vWeekEndDate)','DD/MM/YYYY');

Let vMaxDate=Peek('MaxDateTime',-1);

Let vMaxDateDB=Date('$(vMaxDate)','DD/MM/YYYY');

LOAD *,

          LotStartDateTime AS TempLotStartDateTime

;

SQL SELECT *

FROM "Split Data".dbo."Week2"

Where

CONVERT(nvarchar(10),LotStartDateTime,103) >= '$(vMaxDateDB)'

and 

CONVERT(nvarchar(10),LotStartDateTime,103) <= '$(vWeekEndDateDB)'

qvw format are like this:

SET ThousandSep=',';

SET DecimalSep='.';

SET MoneyThousandSep=',';

SET MoneyDecimalSep='.';

SET MoneyFormat='Rs. #,##0.00;Rs. -#,##0.00';

SET TimeFormat='hh:mm:ss';

SET DateFormat='DD-MM-YYYY';

SET TimestampFormat='DD-MM-YYYY hh:mm:ss[.fff]';

SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec';

SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';

sivarajs
Specialist II
Specialist II

Can u try this...

from ....

where date(LotStartDateTime)=date(to_date('$(vMaxDate)','yyyy-mm-dd') )

Sivaraj S

Not applicable
Author

Still no use.

Untitled.png

sivarajs
Specialist II
Specialist II

remove date() function just compare two dates like

where LotStartDateTime=to_date('$(vMaxDate)','yyyy-mm-dd')

Not applicable
Author

No this error:

Untitled.png

Not applicable
Author

What i'm doing now is instead fo retriving less than weekend data. I'm trying to compare with particualar weeknumber. But i've seen that qlikview is reading the weeknumbers differently and sql reading weeknumbers differently.

For eg:

SELECT *

  FROM [Split Data].[dbo].[Week2]

  where

  DATENAME(WEEK,LotStartDateTime) = DATENAME(WEEK,'2011-06-27 00:00:00')

here week number is 27

It retrives the dates from 2011-06-26 to 2011-07-02

But in qlikview if you use the below code

Load * from

table1.qvd

where

Week(LotStartDateTime) = 27

It retrives the dates from 2011-06-27 to 2011-07-03

here week number is 27

This creates a problem for my incremental process for weekwise qvd files. How can i control this.