PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → HFSQL - Query for a particular Month in Date Field
HFSQL - Query for a particular Month in Date Field
Iniciado por guest, 06,abr. 2015 13:35 - 5 respuestas
Publicado el 06,abril 2015 - 13:35
I am developing a mobile app for Android using WM17.

I want to build a SQL statement that will fetch records only for a given month irrespective of Year by querying the date field in the data file.

But I am not able to do this.

How can we write SQL statement that will do this?

TIA

Yogi Yang
Publicado el 06,abril 2015 - 16:35
Hi Yogi

In sql ther is a statement LEFT.

This you can uses for instance to get the year use:

Left( file.datefield, 4 ) this trims out the year

If you want the year and month

Left( file.datefield, 6) this trims out the year and the month

"YYYYMMDD"

In the query edito you can select calculated Item and then add what I just described. And give the nw row added a name like month or year.
You coudl also write the SQL yoursef. Then it would be something lie this


SELECT
LEFT(file.datefield,6 ) AS Month ,

This is if you want to call the item "Month"

regards

Allard
Publicado el 06,abril 2015 - 16:43
If your db is in hfsql you can use substr.

for april:
where substr(yor_date_field,5,2) = '04'
Publicado el 06,abril 2015 - 17:04
Allard,

Thanks for the tip. But I have already tried this and it is not working so I had to post here as the last resort.

When we use WM emulator everything seem to work properly but as soon as we compile the APK and install it on mobile and run it, it throws error and crashes.

TIA

Yogi Yang
Publicado el 07,abril 2015 - 14:37
what are the error?

Regards

Allard
Publicado el 08,abril 2015 - 13:28
Anyways I have solved the problem in a different way.

Instead of trying to retrieve data based on Month I have built the query to get rows between two dates. I am calculating the start and end dates based on selected month by user.

Thanks everyone for trying to help me out.

TIA

Yogi Yang