Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Adding a Year Range to DB
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Adding a Year Range to DB

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Adding a Year Range to DB
    Posted: 19 February 2005 at 3:18pm
I would like to add a year range to a database. The field names are ClassID (primary key) and Year. I don't want to have to add all years to the table. For example, I would like to add all years from 1970 to 2005. How can I add all of the years from 1970 to 2005 to the database without having to manually add them. I want to do this in ASP. Can someone please help me with this?
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 19 February 2005 at 3:30pm
use a inset query with the value of the year field

something like this

Years Difference = 35

then do a loop and on every loop where you insert a record -1 from the Years Difference.

and set the date value for the database NOW() - year Date difference.

and that way youll add the 35 years gap..

im not sure bit i had problems when trying to insert more than 20 records at once.. might be ok ..
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 19 February 2005 at 11:01pm

Here's my code:

 dim FirstYear, LastYear
FirstYear = Request.Form("txtFirstYear") - 1975
LastYear = Request.Form("txtLastYear") - 2005
Dim I
For I = FirstYear to LastYear
If Trim(FirstYear) > "" then
rs.AddNew
rs("Year")= I
rs.Update
End If Next
 
It worked. What do you think about the way I got it to work. Do you think that there will ever be problems with the code that I used?
 


Edited by Misty - 19 February 2005 at 11:45pm
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 10:50am
that looks ok

remember to close the connection after the procedure
Back to Top
Bluefrog View Drop Down
Senior Member
Senior Member


Joined: 23 October 2002
Location: Korea, South
Status: Offline
Points: 1701
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bluefrog Quote  Post ReplyReply Direct Link To This Post Posted: 20 February 2005 at 5:23pm
Put in some error checking to make sure that you don't end up with some silly amount of loops. ASP doesn't have anything like an Application.DoEvents() method, so it can time out if it is busy for a long time. A small number is fine, but if you get into long procedures with lots of inserts, then you could run into problems. 30 is small, but a few hundred or few thousand could get you in trouble.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.