Advertisement

04.29.2008 at 08:11PM PDT, ID: 23364305
[x]
Attachment Details

Adding a New Column to Stored Procedure

Asked by wdarnellg in MS SQL Server, SQL Server 2005

I am trying to change a working stored procedure by adding a field. I need to get the data from the field "Size" to go with the other data. The 'Size' field is in the OrderDetails table in the subquery. I get an error when I try to execute the query:
Column 'bbiStore_tbl_OrderDetails.Size' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 116, Level 16, State 1, Procedure bbiStoresp_OrdersGetInfo, Line 5
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Can someone help me with the correct syntax?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
ALTER PROCEDURE [dbo].[bbiStoresp_OrdersGetInfo]
(@OrderID int)
AS
-- Get list of orders
SELECT OrderID, 
	(SELECT Size, SUM(Subtotal) FROM bbiStore_tbl_OrderDetails WHERE OrderID = @OrderID)
	AS TotalAmount
	,DateCreated
	,DateShipped
	,Verified
	,Completed
	,Canceled
	,Comments
	,CustomerName
	,ShippingAddress
	,CustomerEmail
FROM bbiStore_tbl_Orders
WHERE OrderID = @OrderID
[+][-]04.29.2008 at 08:20PM PDT, ID: 21467863

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 08:29PM PDT, ID: 21467896

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 08:31PM PDT, ID: 21467904

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 08:37PM PDT, ID: 21467927

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 08:40PM PDT, ID: 21467934

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 08:42PM PDT, ID: 21467941

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 08:44PM PDT, ID: 21467944

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Server 2005
Sign Up Now!
Solution Provided By: Goodangel
Participating Experts: 3
Solution Grade: B
 
 
[+][-]04.29.2008 at 08:48PM PDT, ID: 21467953

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.29.2008 at 09:08PM PDT, ID: 21468011

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628