Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Location
    Malaysia
    Posts
    25

    Exclamation Unanswered: 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& "'

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

  3. #3
    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
    %>

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

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

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •