SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Each GROUP BY expression must contain at least one column that is not an outer reference.


Each GROUP BY expression must contain at least one column that is not an outer reference.

Author
Message
Anamika
Anamika
Mr or Mrs. 500
Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)

Group: General Forum Members
Points: 598 Visits: 1026
Hi,


i'm raising the summary tables by using the following query,


INSERT INTO ClientTbl_SummarySalesMonthTY
([RetailerKey]
,[ProductLevel1]
,[AttributeValue]
,[Month]
,[Year]
,[SalesinUnits]
,[GrossSalesValueinDollars]
,[NetSaleValue]
,[StockOnHandinUnits]
,[StockOnHandinDollars]
,[StockOnOrderinUnits]
,[StockOnOrderinDollars]
,[ReplenishmentType]
,[ProductStatus])
select p.Retailerkey
,'Category'
,p.Category
,c.MonthNumRetailYear
,c.RetailYear
,sum(f.[Quantity Sold])
,sum(f.[Gross Sales Value Incl. Tax])
,sum(f.[Net Sales Value Incl. Tax])
,sum(f.[Store Stock Units on Hand])
,sum(f.[Store Stock On Hand Value Excl. Tax])
,sum(f.[Store Stock Units on Order])
,sum(f.[Store Stock On Order Value Excl. Tax])
,p.ReplenishmentType
,P.ProductStatus

from ClientAdmin.dbo.ClientTbl_DimProduct p
inner join ClientAdmin.dbo.ClientTbl_DimCalendar c
on p.retailerkey = c.retailerkey
inner join ClientAdmin.dbo.ClientTbl_FactSalesStock f
on p.productkey =f.productkey and p.retailerkey =f.retailerkey and c.calendarkey=f.calendarkey

group by p.Retailerkey
,'Category'
,p.Category
,c.MonthNumRetailYear
,c.RetailYear
,p.ReplenishmentType
,P.ProductStatus

and getting the following error

Msg 164,
Each GROUP BY expression must contain at least one column that is not an outer reference.

Early help is highly appreciated.

Thanks
Regards
Viji
Mark Cowne
Mark Cowne
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3129 Visits: 24107
Remove 'Category' from your GROUP BY clause

____________________________________________________

Deja View - The strange feeling that somewhere, sometime you've optimised this query before

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537




Anamika
Anamika
Mr or Mrs. 500
Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)

Group: General Forum Members
Points: 598 Visits: 1026
gr8 it works

thanks a lot Mr. Mark
Viji
sandeep.cs3
sandeep.cs3
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 30
Good info about this topic is discussed at:

http://www.a2zmenu.com/Blogs/SQL/Each-GROUP-BY-expression-must-contain-at-least-one-column-that-is-not-an-outer-reference.aspx
Cadavre
Cadavre
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3918 Visits: 8472
sandeep.cs3 (12/13/2011)
Good info about this topic is discussed at:

SNIP


This thread is from 2008. . .


Forever trying to learn

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better, quicker answers on SQL Server performance related questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



If you litter your database queries with nolock query hints, are you aware of the side effects?
Try reading a few of these links...

(*) Missing rows with nolock
(*) Allocation order scans with nolock
(*) Consistency issues with nolock
(*) Transient Corruption Errors in SQL Server error log caused by nolock
(*) Dirty reads, read errors, reading rows twice and missing rows with nolock


Craig Wilkinson - Software Engineer
LinkedIn
rshadman
rshadman
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 43
and yet that link was still helpful to me today, in 2012 Smile
inevercheckthis2002
inevercheckthis2002
SSC-Enthusiastic
SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)

Group: General Forum Members
Points: 173 Visits: 474
..and that link is no longer valid, in 2014
PringleEater
PringleEater
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 114
but link is valid in 2016
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search