Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
dickelsa
Contributor

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

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

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
Valued Contributor

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

you can consider Date from now then you can use

Load Date(Today()) as DateField


dickelsa
Contributor

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

Thanks! I think this will do the trick.

Do you know know how to extract the time also?

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

Look again


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


talk is cheap, supply exceeds demand
dickelsa
Contributor

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

o sorry, I missed that, shame on me ;p

thanks!

dickelsa
Contributor

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

it does not work actually..

Community Browser