CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 Insert date range - multiple dates - two tables

Print topic Send  topic

Author Message
djgjohng

Posts: 28
Posted: 10/27/2006, 1:14 AM

Here's something I seriously struggled with - not being a programmer. I searched the web for solutions (found virtually nothing) and received some ideas from a PHP guy. Luckily I can afford to spend countless hours figuring this stuff out.

Let's say you have two dates in a form that you are inserting into one table. You then want to split that range up into individual dates to insert into another table:

(Set up an 'After Execute Insert' event on the form)

global $DBConnection1;
global $[YOURFORM];

$last_insertedID = CCDLookUp("max(recID)", "table1", "", $DBConnection1);
$first_date = CCDLookUp("datefrom","table1","recID=". $DBConnection1->ToSQL($last_insertedID, ccsInteger), $DBConnection1);
$last_date = CCDLookUp("dateto","table1","recID=". $DBConnection1->ToSQL($last_insertedID, ccsInteger), $DBConnection1);
$db = new clsDBConnection1();
$basedate = $first_date;

do {
$SQL = "INSERT INTO table2(recID, datefield) ".
"VALUES (". $db->ToSQL($last_insertedID,ccsInteger) .",". $db->ToSQL($basedate,ccsDate).")";
$db->query($SQL);
list($year, $month, $day) = split("-", $basedate);
$basedate= date("Y-m-d", mktime(0,0,0, $month, $day+1, $year));
} while ($basedate<= $last_date);
$db->close();


Has many applications.

Enjoy!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.