Problem with SQL Syntax

Questions, tips and tricks and techniques for scripting in Servoy

Problem with SQL Syntax

Postby tommygill » Thu Aug 12, 2010 4:57 pm

Hi All

This forum has been most helpful so I will post another small problem.

The following code, which contains SQL statements, works great.
Code: Select all
globals.current_donation_date = donation_date;
   //This query will return the records for this report
   var query = "SELECT DISTINCT detail_query_totals FROM donation_detail WHERE detail_date = ?";
   //This query will return the PK's of the records for this report
   var query_pk = "SELECT donation_detail_id FROM donation_detail WHERE donation_detail_id IN " + "(SELECT MIN (donation_detail_id) FROM donation_detail WHERE detail_date = ? GROUP BY detail_query_totals)" + "ORDER BY detail_query_totals asc";
   var args = new Array();
   args[0] = utils.dateFormat(donation_date, 'MM/dd/yyyy');
   var dataset = databaseManager.getDataSetByQuery(databaseManager.getDataSourceServerName(controller.getDataSource()),query,args,-1);
   var ds_pk = databaseManager.getDataSetByQuery(databaseManager.getDataSourceServerName(controller.getDataSource()),query_pk,args,-1);
   var recCount = dataset.getMaxRowIndex();
   //Load the desired records into a form's foundset using the PK's from ds_pk
   forms.Report_Current_Receipt_Totals.controller.loadRecords(ds_pk);
   //put some code here to do what you want with dataset
   forms.Report_Current_Receipt_Totals.controller.showPrintPreview();

As you can see, both statements us the args array which contains one item, a date. I would like to modify the statement to retrieve all the records where the date is between a start date and an end date. Can this be done using the args array or do I need to recode a different way?

Thanks for all your help.
Tom

Mac OS X 10.6.7
Servoy version 5.2.0 -build 997
Java Version 1.6.0_20
User avatar
tommygill
 
Posts: 110
Joined: Thu Jan 27, 2005 1:38 pm
Location: Columbus, Indiana, USA

Re: Problem with SQL Syntax

Postby ROCLASI » Thu Aug 12, 2010 5:04 pm

Hi Tom,

You can use the following syntax:
Code: Select all
SELECT * FROM myTable WHERE myDate BETWEEN ? AND ?

This way you simply pass the start and end date.

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: Problem with SQL Syntax

Postby tommygill » Sun Aug 15, 2010 6:34 pm

Thanks For the Help. It has taken a lot of time to get back to you because the debug feature stopped working, which is not your fault. Your suggestion of BETWEEN & AND was quite successful. Thanks so much.
Tom

Mac OS X 10.6.7
Servoy version 5.2.0 -build 997
Java Version 1.6.0_20
User avatar
tommygill
 
Posts: 110
Joined: Thu Jan 27, 2005 1:38 pm
Location: Columbus, Indiana, USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests