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. Bastardized query into one query

Bastardized query into one query

Scheduled Pinned Locked Moved Database
databasequestion
4 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.
  • N Offline
    N Offline
    Nino_1
    wrote on last edited by
    #1

    Hi, I have a query that needs to act as one single query: Here's the first part:

    select distinct a.officer as Officer, count(distinct(j.fstatus))as Escrow_Type, count(distinct(j.amount))as Amount, count(distinct(d.open_date))as [Open], count(distinct(d.close_date)) as Closed, count(distinct(can_date))as Cancelled

    from a10 a
    inner join escrow d on a.escrow = d.escrow
    inner join e120 j on j.escrow = d.escrow where j.id_scr = 'e21 ' and j.fstatus = 'PAID' group by a.officer

    Here's the second part:

    x.amount as New from escrow k inner join e120 x on k.escrow = x.escrow
    inner join a10 g on x.escrow = g.escrow where k.ftype = 'S' group by x.amount, g.officer having x.amount <> 0.0

    Here's the third part:

    b.amount as Refi from escrow c inner join e120 b on c.escrow = b.escrow
    inner join a10 f on c.escrow = f.escrow where c.ftype = 'R' group by b.amount, f.officer having b.amount <> 0.0

    Is there a way to make this act as one single query? I have an application that reads only one cursor at a time. Thanks In Advance,

    Nino

    E M 2 Replies Last reply
    0
    • N Nino_1

      Hi, I have a query that needs to act as one single query: Here's the first part:

      select distinct a.officer as Officer, count(distinct(j.fstatus))as Escrow_Type, count(distinct(j.amount))as Amount, count(distinct(d.open_date))as [Open], count(distinct(d.close_date)) as Closed, count(distinct(can_date))as Cancelled

      from a10 a
      inner join escrow d on a.escrow = d.escrow
      inner join e120 j on j.escrow = d.escrow where j.id_scr = 'e21 ' and j.fstatus = 'PAID' group by a.officer

      Here's the second part:

      x.amount as New from escrow k inner join e120 x on k.escrow = x.escrow
      inner join a10 g on x.escrow = g.escrow where k.ftype = 'S' group by x.amount, g.officer having x.amount <> 0.0

      Here's the third part:

      b.amount as Refi from escrow c inner join e120 b on c.escrow = b.escrow
      inner join a10 f on c.escrow = f.escrow where c.ftype = 'R' group by b.amount, f.officer having b.amount <> 0.0

      Is there a way to make this act as one single query? I have an application that reads only one cursor at a time. Thanks In Advance,

      Nino

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      I must ask why is the second part using different alias names from the third part? The queries seem to only differ by escrow.ftype.

      A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

      N 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        I must ask why is the second part using different alias names from the third part? The queries seem to only differ by escrow.ftype.

        A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

        N Offline
        N Offline
        Nino_1
        wrote on last edited by
        #3

        My reasoning behind that was to get the values of two different fields. The second part is getting the values for the 'S' which is defined as a "New" escrow sale. The third part is getting the values for the 'R' which is defined as a "Refi" or refinance. After these two fields are retrieved they are then added based on the escrow field based on the join.

        Nino

        1 Reply Last reply
        0
        • N Nino_1

          Hi, I have a query that needs to act as one single query: Here's the first part:

          select distinct a.officer as Officer, count(distinct(j.fstatus))as Escrow_Type, count(distinct(j.amount))as Amount, count(distinct(d.open_date))as [Open], count(distinct(d.close_date)) as Closed, count(distinct(can_date))as Cancelled

          from a10 a
          inner join escrow d on a.escrow = d.escrow
          inner join e120 j on j.escrow = d.escrow where j.id_scr = 'e21 ' and j.fstatus = 'PAID' group by a.officer

          Here's the second part:

          x.amount as New from escrow k inner join e120 x on k.escrow = x.escrow
          inner join a10 g on x.escrow = g.escrow where k.ftype = 'S' group by x.amount, g.officer having x.amount <> 0.0

          Here's the third part:

          b.amount as Refi from escrow c inner join e120 b on c.escrow = b.escrow
          inner join a10 f on c.escrow = f.escrow where c.ftype = 'R' group by b.amount, f.officer having b.amount <> 0.0

          Is there a way to make this act as one single query? I have an application that reads only one cursor at a time. Thanks In Advance,

          Nino

          M Offline
          M Offline
          Michael Potter
          wrote on last edited by
          #4

          I might ask why the second & third part have 'GROUP BY' & 'HAVING' clauses when there is only 1 field selected and it is not an aggregate. I also question the counting of distinct dates in the first query. Can't an officer handle more then one open/closed/cancelled transaction per day?

          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