If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Select from table A and insert into table B

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-13-04, 04:11
ayu ayu is offline
Registered User
 
Join Date: Apr 2004
Location: Malaysia
Posts: 25
Exclamation Select from table A and insert into table B

Can somebody give me an idea what should I write my sql statement.
I want to select all data form table A with condition check year. When record find, I want to insert it into table B

SELECT * FROM tableA INSERT INTO tableB WHERE year(tableA.tarikh) = '" & getyear& "'
Reply With Quote
  #2 (permalink)  
Old 05-13-04, 10:53
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
You were close, just switched around...

INSERT INTO MyTable (PriKey, Description)
SELECT ForeignKey, Description
FROM Criteria
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #3 (permalink)  
Old 05-13-04, 20:41
ayu ayu is offline
Registered User
 
Join Date: Apr 2004
Location: Malaysia
Posts: 25
I had try. I's look ok but no data transfer into table A. I enclose my coding for you. For your info the datatype for tarikhmula is date/time(short date)

<%
Dim gettahun
Dim db
Dim sq
Dim rs

gettahun = request.form("tahun")

set db = Server.CreateObject("ADODB.Connection")
db.Open "data"

sq = "INSERT INTO Arkib(nostaffuitm, tarikhmula,hingga, jenis, jumcuti, catitan) SELECT nostaffuitm, tarikhmula, hingga, jenis, jumcuti, catitan FROM RekodCuti WHERE year(tarikhmula) = '" & gettahun & "'"
set rs = db.execute(sq)
db.close
%>
Reply With Quote
  #4 (permalink)  
Old 05-14-04, 01:42
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
sq = "INSERT INTO Arkib(nostaffuitm, tarikhmula,hingga, jenis, jumcuti, catitan) SELECT nostaffuitm, tarikhmula, hingga, jenis, jumcuti, catitan FROM RekodCuti WHERE year(tarikhmula) = YEAR('" & gettahun & "')"
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #5 (permalink)  
Old 05-14-04, 03:18
ayu ayu is offline
Registered User
 
Join Date: Apr 2004
Location: Malaysia
Posts: 25
for you info the gettahun I get it when I insert in previous page. For eg. I just type 2003 and it post the the second page.
The second page will check the year using tarikhmula that I save in my table with datatype date. If the condition true, it will insert all record in table A into table B for year(tarikhmula) = 2003.
If you can help me sovle this problem, I think my system can be finish because I'm now stuck at all condition using date.
Reply With Quote
  #6 (permalink)  
Old 05-17-04, 13:02
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Try taking the single quotes off of "gettahun" in the query:

sq = "INSERT INTO Arkib(nostaffuitm, tarikhmula,hingga, jenis, jumcuti, catitan) SELECT nostaffuitm, tarikhmula, hingga, jenis, jumcuti, catitan FROM RekodCuti WHERE year(tarikhmula) = " & gettahun
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On