Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    5

    Unanswered: Tough SQL statement

    Hi all
    Having a hard time figuring out the correct syntax for this SQL statement

    2 tables
    tblMaster
    tblData

    Get all SS in tblMaster that are less than the Sum of Forradssaldo in tblData
    That corresponds with Artikelnr in both tblMaster and tblData

    Below is how far I've come
    Anyone got any pointers, I'd be most appeciative.

    strSQL = "SELECT ID, Artikelnr, SS FROM tblMaster WHERE SS " & _
    "< (SELECT SUM(Forradssaldo) AS SUMDATA, Artikelnr FROM tblData WHERE Artikelnr = Artikelnr)"
    --

    Mvh
    Jon

    jonny.hakansson@comhem.se

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You're awfully close.

    strSQL = "SELECT ID, Artikelnr, SS FROM tblMaster WHERE SS " & _
    "< (SELECT SUM(Forradssaldo) FROM tblData WHERE tblData.Artikelnr = tblMaster.Artikelnr)"
    Last edited by Teddy; 03-23-04 at 16:22.

  3. #3
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    5

    I know

    Hi

    It still does'nt work

    Do you have any other methods to solve the problem

    Thanks again.
    Jon

    jonny.hakansson@comhem.se

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    PHP Code:
    select M.ID
         
    M.Artikelnr
         
    M.SS 
      from tblMaster  M
    inner
      join tblData  D
        on M
    .Artikelnr D.Artikelnr
    group
        by M
    .ID
         
    M.Artikelnr
         
    M.SS 
    having M
    .SS sum(D.Forradssaldo
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Oct 2003
    Location
    Sweden
    Posts
    5
    Thanks r937

    It works, I'am on way..

Posting Permissions

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