Click to See Complete Forum and Search --> : sql Update


gop373
03-04-2005, 03:25 AM
I have to update the date from 1 to 31. I have to update these information into 100 tables. Each table consistes of id, date and price
id:: auto
date:: date/time
price:: number

In other word I have to write these date into each table
2005/03/01
2005/03/01
...
.
.
.
.until
2005/03/31
How can I write sql statement. (I use Microsoft access and asp)

buntine
03-04-2005, 03:55 AM
You will need a loop and some date handling functions.

Dim conn
Set conn = Server.CreateObject("ADODB.RecordSet")
conn.Open("DBQ=" & Server.MapPath("yourDatabase.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}")

Dim dte: dte = "2005/03/01"
For i = 1 To 32
conn.Execute("UPDATE tableName SET [date] = #" & dte & "#;")
dte = DateAdd("d", 1, dte)
Next

Something like that should work.

Regards.

gop373
03-04-2005, 04:49 AM
I tired this..
<!--#include file="connect.asp"-->
<%
Dim dte,i
dte = "2005/03/01"
For i = 1 To 31
sql="UPDATE BA_price set dat = #" & dte & "# where id="&i&""
conn.execute(sql)
dte = DateAdd("d", 1, dte)
Next
%>

The result is this
id dat
1 2005/03/01
2 2005/02/03
3 2005/03/03
4 2005/04/03
5 2005/05/03
6 2005/06/03
7 2005/07/03
8 2005/08/03
9 2005/09/03
10 2005/10/03
11 2005/11/03
12 2005/12/03
13 2005/03/13
14 2005/03/14
15 2005/03/15
16 2005/03/16
.
.
31 2005/03/31



I want somthing like this
id dat
1 2005/03/01
2 2005/03/02
3 2005/03/03
.
.

31 2005/03/31
Anyone can help !!