Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Sytntax Error

Hello,

LOAD application_no,

     paycode as %PAYCODE,

     request_id,

//     request_date,

     date(leave_from,'DD-MMM-YYYY') as leave_from,

     year(leave_from) as LeaveYear,

     month(leave_from) as LeaveMonth,

     day(leave_from) as LeaveDay,

     leave_to,

     //leave_to,

     leavecode as LEAVECODE,

//     halfday,

     leavedays,

     //if(leavecode='CL', sum(leavedays),'0') as CLAccrued,

     Sum(if(leavecode='CL', leavedays)),

     userremarks

FROM

$(Vrawqvdspath)\LeaveRequest.qvd

(qvd) Group by paycode, month(leave_from);

Can somebody tell me what is the error in this code?

It is giving me error.

Regards,

Balraj

10 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

When using grouping, every field not in an aggregation function (Sum(if...) in your case) must be listed in the group by clause

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Anonymous
Not applicable
Author

Hello,

You meant to say, leavecode and leavedays should be listed in grouping?

mjayachandran
Creator II
Creator II

Try this"

LOAD application_no,

     paycode as %PAYCODE,

     request_id,

//     request_date,

     date(leave_from,'DD-MMM-YYYY') as leave_from,

     year(leave_from) as LeaveYear,

     month(leave_from) as LeaveMonth,

     day(leave_from) as LeaveDay,

     leave_to,

     //leave_to,

     leavecode as LEAVECODE,

//     halfday,

     leavedays,

     //if(leavecode='CL', sum(leavedays),'0') as CLAccrued,

     Sum(if(leavecode='CL', leavedays)),

     userremarks

FROM

$(Vrawqvdspath)\LeaveRequest.qvd

(qvd)

Group by     paycode,

            month(leave_from),

            application_no,

            request_id,

             date(leave_from,'DD-MMM-YYYY'),

             year(leave_from),

             day(leave_from),

             leave_to,

             leavecode

             leavedays,

             userremarks  ;

So, In Groupby you should have all the field which you are not aggregrating

its_anandrjs

Hi,

When using Group by clause in the load you have to introduce all the fields available in the table see example otherwise use resident table load statement.

LOAD

     application_no,

     paycode as %PAYCODE,

     request_id,

//   request_date,

     date(leave_from,'DD-MMM-YYYY') as leave_from,

     year(leave_from) as LeaveYear,

     month(leave_from) as LeaveMonth,

     day(leave_from) as LeaveDay,

     leave_to,

     //leave_to,

     leavecode as LEAVECODE,

//   halfday,

     leavedays,

     //if(leavecode='CL', sum(leavedays),'0') as CLAccrued,

     Sum(if(leavecode='CL', leavedays)),

     userremarks

FROM

$(Vrawqvdspath)\LeaveRequest.qvd

(qvd) Group by 

     application_no,

     paycode,

     request_id,

     date(leave_from,'DD-MMM-YYYY'),

     year(leave_from),

     month(leave_from),

     day(leave_from),

     leave_to,

     leavecode,

     leavedays,

     userremarks;

Not applicable
Author

What columns (other than aggregation function)  you are selecting in Load statement must be present in group by Clause.

Not applicable
Author

Apart from the above, one more cent is

date(leave_from,'DD-MMM-YYYY') as leave_from, -- is wrong


it should be


date#(leave_from,'DD-MMM-YYYY') as leave_from,


date#() is date formatting function. Please refer to Reference Manual


I guess you wanted to format the "leave_from" field in your load.


Thanks

Sri

Anonymous
Not applicable
Author

Anand,

Should I include leavecode and leavedays as well, as you mentioned?

Anonymous
Not applicable
Author

Thanks Anand, Its done.

Anonymous
Not applicable
Author

Thanks Mahesh, Its done.