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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Complex SQL query... [modified]

Complex SQL query... [modified]

Scheduled Pinned Locked Moved Database
databasequestionannouncement
5 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.
  • R Offline
    R Offline
    ruanr
    wrote on last edited by
    #1

    SQL novice here.. Hi, I'm having trouble formulating an SQL query and tbh I'm not even sure if its possible to do what I'm trying to do [without a cursor]. I have two tables with a standard 1->M relationship. If a certain field in ALL the linked records are set to a certain value, I need to update a field in the parent record, if the field is set to a different value in one of the linked records, i do nothing. How should I phrase the query? Edit for clarification: Lets say it is a Client table, with a related Tasks table, and the intermediate ClientTasks table. If all the Tasks related to a Client are marked as done, I need to update a field in the Client's record to mark the client as having no outstanding tasks. Thanks in advance..

    modified on Tuesday, June 17, 2008 4:26 AM

    J A 2 Replies Last reply
    0
    • R ruanr

      SQL novice here.. Hi, I'm having trouble formulating an SQL query and tbh I'm not even sure if its possible to do what I'm trying to do [without a cursor]. I have two tables with a standard 1->M relationship. If a certain field in ALL the linked records are set to a certain value, I need to update a field in the parent record, if the field is set to a different value in one of the linked records, i do nothing. How should I phrase the query? Edit for clarification: Lets say it is a Client table, with a related Tasks table, and the intermediate ClientTasks table. If all the Tasks related to a Client are marked as done, I need to update a field in the Client's record to mark the client as having no outstanding tasks. Thanks in advance..

      modified on Tuesday, June 17, 2008 4:26 AM

      J Offline
      J Offline
      joemonvarghese80 yahoo co in
      wrote on last edited by
      #2

      can u clarify Your question regards Joe

      R 1 Reply Last reply
      0
      • J joemonvarghese80 yahoo co in

        can u clarify Your question regards Joe

        R Offline
        R Offline
        ruanr
        wrote on last edited by
        #3

        okay, see edit..

        J 1 Reply Last reply
        0
        • R ruanr

          okay, see edit..

          J Offline
          J Offline
          joemonvarghese80 yahoo co in
          wrote on last edited by
          #4

          hi from your clarification i understand that you have to update a master table an a child table...you can handle this either in Stored procedure or in Code itself Regards Joe

          1 Reply Last reply
          0
          • R ruanr

            SQL novice here.. Hi, I'm having trouble formulating an SQL query and tbh I'm not even sure if its possible to do what I'm trying to do [without a cursor]. I have two tables with a standard 1->M relationship. If a certain field in ALL the linked records are set to a certain value, I need to update a field in the parent record, if the field is set to a different value in one of the linked records, i do nothing. How should I phrase the query? Edit for clarification: Lets say it is a Client table, with a related Tasks table, and the intermediate ClientTasks table. If all the Tasks related to a Client are marked as done, I need to update a field in the Client's record to mark the client as having no outstanding tasks. Thanks in advance..

            modified on Tuesday, June 17, 2008 4:26 AM

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            There are several ways, but the quickest (assuming decent indexing) should be along the lines of

            update client
            set alldone = 'Y' -- signifies no outstanding tasks
            from client c
            where not exists (select 1 from clienttasks t where t.clientid = c.clientid and t.alldone = 'n')

            This may not mathc your tables, but you should get the general idea I hope.

            Bob Ashfield Consultants Ltd

            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