Query to return data for current year

Questions and answers regarding general SQL and backend databases

Query to return data for current year

Postby hardina09 » Fri Sep 21, 2012 8:31 pm

In my foundset I need to load all records that are for current year.
//curYear=2012
//start_dts is column in my table.
Code: Select all
foundset.loadRecords('SELECT id from tablename WHERE datepart(yyyy,start_dts)=?',[curYear]


Above syntax is incorrect. anyone please correct me where I went wrong.

Thank you in advance.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm

Re: Query to return data for current year

Postby ROCLASI » Fri Sep 21, 2012 10:12 pm

Hi,

If you are doing this in PostgreSQL then the syntax is the following:
Code: Select all
foundset.loadRecords("SELECT id from tablename WHERE date_part('year',start_dts)=?", [curYear])

For more information check out the excellent documentation:
http://www.postgresql.org/docs/9.1/stat ... etime.html

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Query to return data for current year

Postby hardina09 » Tue Sep 25, 2012 2:21 pm

Great ROCLASI. Thank you.
hardina09
 
Posts: 62
Joined: Tue Apr 24, 2012 9:46 pm


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 6 guests

cron