Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:19:38+00:00 2026-06-01T01:19:38+00:00

I got this Sql Query declare @ProductNo int set @ProductNo = 123 select o.OrderNo,

  • 0

I got this Sql Query

declare @ProductNo int

set @ProductNo = 123

select o.OrderNo, OrderDate, ol.Amount
from OrderLine ol
inner join [Order] o on ol.OrderNo = o.OrderNo
where ol.ProductNo = @ProductNo

Now my question is, that I would like to return a sum for each Order.
I tryid changing my query to

select o.OrderNo, OrderDate, ol.Amount,(select sum(ol.Amount * ol.UnitPrice) as OrderTotal from OrderLine oll where oll.OrderNo = o.OrderNo)
    from OrderLine ol
    inner join [Order] o on ol.OrderNo = o.OrderNo
    where ol.ProductNo = @ProductNo

But that’s not running, so I’m hoping someone could help me complete my query

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:19:39+00:00Added an answer on June 1, 2026 at 1:19 am

    In your sub-select you’re referring to ol.Amount * ol.UnitPrice, but your OrderLine table is called oll in the sub-query, so the following should do:

    select o.OrderNo, OrderDate, ol.Amount,(select sum(oll.Amount * oll.UnitPrice) from OrderLine oll where oll.OrderNo = o.OrderNo) as OrderTotal
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got this SQL query where post_title taken from $_GET $sql = SELECT ID
I've got this dynamic t-sql: declare @sql nvarchar(max) set @sql = N' insert into
I’ve got a basic SQL query that looks like: SELECT TOP 1 [geom].STBuffer(500) FROM
I've got an SQL query that looks like this: INSERT INTO DB..incident ( incident_number
Got a complex SELECT query, from which I would like to insert all rows
I got this a problem, I need translate this SQL Query to Criteria, but
I've got this method that returns a Linq-to-SQL query for all the rows in
It's all in the title really. I've got this SQL query, ugly I know,
I've got this code here: SqlCommand CodeStatus = new SqlCommand(SQL, DB); DB.Open(); Reader =
I've got a SQL statement in SQL Server 2005 that looks something like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.