Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to update statement from subselect?

how to update statement from subselect?

Scheduled Pinned Locked Moved Database
databasehelptutorialquestionannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eunice VB junior
    wrote on last edited by
    #1

    Hi, I wish to update 3 data to udtstudent. These 3 datas are taken from udtQuestionHistory. How should i write?? I tried the below query. But it doesn't work. Can anyone help me? Thanks in advance. my query: update udtstudent set(score,Testdate,MarkDate)in(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35 Thanks.

    M G 2 Replies Last reply
    0
    • E Eunice VB junior

      Hi, I wish to update 3 data to udtstudent. These 3 datas are taken from udtQuestionHistory. How should i write?? I tried the below query. But it doesn't work. Can anyone help me? Thanks in advance. my query: update udtstudent set(score,Testdate,MarkDate)in(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35 Thanks.

      M Offline
      M Offline
      MatthysDT
      wrote on last edited by
      #2

      Eunice (VB junior) wrote:

      update udtstudent set(score,Testdate,MarkDate)in(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35

      Try this: update udtstudent set a.score=b.scoreSum,a.TestDate=b.Testdate a.MarkDate = b.MarkDate from udtstudent a,(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) b where a.TestID =1 and a.EmpNo=35 I didn't test it. Also check your relationships and make certain that only one row is returned from the sub query!

      _______________________________________________________________________ http://www.notreadytogiveup.com/Doubts.aspx[^] "you can't forget something you never knew..." M. Du Toit

      E 1 Reply Last reply
      0
      • E Eunice VB junior

        Hi, I wish to update 3 data to udtstudent. These 3 datas are taken from udtQuestionHistory. How should i write?? I tried the below query. But it doesn't work. Can anyone help me? Thanks in advance. my query: update udtstudent set(score,Testdate,MarkDate)in(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35 Thanks.

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        Try this: update udtstudent set(score,Testdate,MarkDate)= (select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35

        You always pass failure on the way to success.
        E 1 Reply Last reply
        0
        • G GuyThiebaut

          Try this: update udtstudent set(score,Testdate,MarkDate)= (select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35

          You always pass failure on the way to success.
          E Offline
          E Offline
          Eunice VB junior
          wrote on last edited by
          #4

          Hi GuyThieBaut, Thanks for the suggestion. But it doesn't work. Anyway appreciate that. -- modified at 22:21 Monday 8th October, 2007

          G 1 Reply Last reply
          0
          • M MatthysDT

            Eunice (VB junior) wrote:

            update udtstudent set(score,Testdate,MarkDate)in(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) where TestID =1 and EmpNo=35

            Try this: update udtstudent set a.score=b.scoreSum,a.TestDate=b.Testdate a.MarkDate = b.MarkDate from udtstudent a,(select sum(studentscore),TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid) b where a.TestID =1 and a.EmpNo=35 I didn't test it. Also check your relationships and make certain that only one row is returned from the sub query!

            _______________________________________________________________________ http://www.notreadytogiveup.com/Doubts.aspx[^] "you can't forget something you never knew..." M. Du Toit

            E Offline
            E Offline
            Eunice VB junior
            wrote on last edited by
            #5

            Hi EvilNoodle, Thanks for the answer. Initially it doesn't work. But i altered a bit from ur query and it works already. Thanks. Here is the query after modified. update udtstudent set score=b.scoreSum,TestDate=b.Testdate,MarkDate = b.MarkDate from udtstudent a,(select sum(studentscore)as scoreSum,TestDate,MarkDate from udtQuestionHistory where TestID =1 and EmpNo=35 group by empno,testid,testdate,markdate) b where a.TestID =1 and a.EmpNo=35 Thanks for the help.

            1 Reply Last reply
            0
            • E Eunice VB junior

              Hi GuyThieBaut, Thanks for the suggestion. But it doesn't work. Anyway appreciate that. -- modified at 22:21 Monday 8th October, 2007

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #6

              Okay you're welcome (for the code that did not work:(), Well done on cracking this one:)

              You always pass failure on the way to success.
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups