Results 1 to 3 of 3

Thread: [RESOLVED] Sub Query Problem

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Resolved [RESOLVED] Sub Query Problem

    SQL Code:
    1. SELECT SUM(SELECT (Qty * U_cost) as SubCost
    2.        FROM Prod_Detail
    3.        WHERE PCRefNo = @PCRefNo AND Product_Code = @PCode) AS TotalCost
    4. FROM Prod_Detail
    5. WHERE PCRefNo = @PCRefNo AND Product_Code = @PCode

    What problem of my query ?

    Prompt out Incorrect Syntax near the keyword 'SELECT'
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Sub Query Problem

    You can't sum a sub query. If you want to sum the result of multiplying Qty and U_cost then that's exactly what you should do:
    sql Code:
    1. SELECT SUM(Qty * U_cost) AS TotalCost
    2. FROM Prod_Detail
    3. WHERE PCRefNo = @PCRefNo AND Product_Code = @PCode
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Sub Query Problem

    Thanks a lot ,

    Problem Solved ...
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

Posting Permissions

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



Click Here to Expand Forum to Full Width