| |
|
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.
|
 |

05-13-04, 04:11
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Malaysia
Posts: 25
|
|
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& "'
|
|

05-13-04, 10:53
|
|
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.
|
|

05-13-04, 20:41
|
|
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
%>
|
|

05-14-04, 01:42
|
|
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.
|
|

05-14-04, 03:18
|
|
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.
|
|

05-17-04, 13:02
|
|
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.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|