Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us at the Cloud Data and Analytics Tour! REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
dickelsa
Creator
Creator

extracting year, month, day and time form sql load script

Hi all,

I am currently working on something with an script that loads data from an SQL server.

here is a part of the code:

OLEDB CONNECT TO [sql script id];

SQL SELECT * FROM QV1.dbo."newbase_task_template_line_v";

SQL SELECT * FROM QV1.dbo."newbase_holding_v";

SQL SELECT * FROM QV1.dbo."newbase_ticket_strip_v";

SQL SELECT * FROM QV1.dbo."newbase_hrm_header_v";

SQL SELECT * FROM QV1.dbo."newbase_time_registration_v";

Now, when the script loads the data, it çreates fields for the data in above standing files.

For example, the file named newbase_time_registration has fields : 'start time'; 'end time'; 'ammount of hours spent'; etc

The time and date however are not listed in fields 'month', 'year', 'week', 'day' but are all standing in one field combined.

This is very annoying because then you would get a field value that looks like this:

Fri May 18 2012 00:00:00 GMT+0200 (CEST)

My question is: how do I extract the month, day, time and year from this?

normally you can put

Year('date')=Year

but since you cannot see the field headers in the script, it seems a little harder than that.

Any suggestions? please let me know

Thanks in advance

Kind regard

Dick

6 Replies
Gysbert_Wassenaar

You will need to know the field names to be able to process them further. Once you know those you can use preceding loads the create the extra fields:

load *,

    year([start date]) as Year,

    month([start date] as Month,

    day([start date]) as Day,

    ...etc for other dates

load *,

    date#(mid([start time],5,11),'MMM DD YYYY') as [start date];

    time#(mid([start time],17,8),'hh:mm:ss') as [start time];

  ... etc for other dates

SQL SELECT * FROM QV1.dbo."newbase_time_registration_v";


talk is cheap, supply exceeds demand
saumyashah90
Specialist
Specialist

you can consider Date from now then you can use

Load Date(Today()) as DateField


dickelsa
Creator
Creator
Author

Thanks! I think this will do the trick.

Do you know know how to extract the time also?

Gysbert_Wassenaar

Look again


time#(mid([start time],17,8),'hh:mm:ss') as [start time];


talk is cheap, supply exceeds demand
dickelsa
Creator
Creator
Author

o sorry, I missed that, shame on me 😜

thanks!

dickelsa
Creator
Creator
Author

it does not work actually..