Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    14

    Unanswered: whats wrong with this query?

    I am trying to sum a column together. This is what I am doing:

    SELECT
    sum(theoreticalTime= (Select
    sum(rcp.theoreticalTime)

    From
    Traveler_X3 trv Join Recipe_X3 rcp On (trv.RecipeID = rcp.RecipeID)

    Where
    trv.Oper = rtsA.oper And
    trv.RouteGroupID = (
    Select
    rgp.routeGroupID

    From
    Route_Group_X3 rgp

    Where
    rgp.routeGroupName = ( Select
    rtl.RouteGroup

    From
    RouteList_X3 rtl

    WHERE
    rtl.route = rtsA.route
    )
    )
    ))


    FROM
    Routes_X3 rtsA

    where
    rtsA.route=( SELECT
    lhm.route

    FROM
    brettb.pdash2.dbo.lothistorymoves lhm,
    x3oprs x3o

    WHERE
    lhm.lot = 'S6D0IQ002A' AND
    lhm.oper = x3o.oper AND
    lhm.date_time = (SELECT max(date_time) FROM brettb.pdash2.dbo.lothistorymoves lhm, x3oprs x3o WHERE lhm.lot = 'S6D0IQ002A' AND lhm.oper = x3o.oper)
    )

    and rtsA.seq BETWEEN ( SELECT
    seq

    FROM
    Routes_X3

    WHERE
    oper =( SELECT
    lhm.oper

    FROM
    brettb.pdash2.dbo.lothistorymoves lhm

    WHERE
    lhm.lot ='S6D0IQ002A' AND
    lhm.date_time = (SELECT max(date_time) FROM brettb.pdash2.dbo.lothistorymoves lhm WHERE lhm.lot = 'S6D0IQ002A')
    )

    and route=( select top 1
    lhm.route

    FROM
    brettb.pdash2.dbo.lothistorymoves lhm,
    x3oprs x3o

    WHERE
    lhm.lot = 'S6D0IQ002A' AND
    lhm.oper = x3o.oper AND
    lhm.date_time = (SELECT max(date_time) FROM brettb.pdash2.dbo.lothistorymoves lhm, x3oprs x3o WHERE lhm.lot ='S6D0IQ002A' AND lhm.oper = x3o.oper)
    )
    )+1 and 219;


    What i got working was to put the query in a temp table called #temp1 and then run this:
    select sum(theoreticalTime) from #temp1;

    but isnt there a way to do this in one query?

    Thank you for any help

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Dude! You need to learn SQL and you need to start with baby steps! You realize that your entire block of code contains only one "JOIN"? THERE's your problem. Drop the nested queries from your SELECT and WHERE clauses. They make your code look like something by Jackson Pollock.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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