Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Error message

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-10-20 : 10:36:33
Do you have any idea how I can fix this error in the following query:
I know that in table t2 the group by the mentioned column should be placed to be consistent with the columns in table t1 for inner join.

select t1.hts_code
,t1.ust_code
,t1.dist_entry
,t1.con_val_sum_yr
,t2.con_val_yr

from [dev].[sumMontly_imp] t1
inner join
[trade].[ft].[imp_detl_07] t2

on

t1.hts_code = t2.hts_code

where t2.stat_month = '12'
group by t2.hts_code
,t2.ust_code
,t2.dist_entry


Error message is:
Msg 8120, Level 16, State 1, Procedure test, Line 4
Column 'dev.sumMontly_imp.hts_code' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-20 : 10:38:57
i don't see any aggregate function used. What are you trying to do here ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2011-10-20 : 11:10:03
oh Sorry Aggregate is in:
....
,sum(t2.con_val_yr) con_val_yr
....
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-20 : 11:16:20
[code]
select t1.hts_code
,t1.ust_code
,t1.dist_entry
,SUM(t1.con_val_sum_yr) as sum
,SUM(t2.con_val_yr) as con_val_yr
from [dev].[sumMontly_imp] t1
inner join [trade].[ft].[imp_detl_07] t2 on t1.hts_code = t2.hts_code
where t2.stat_month = '12'
group by t1.hts_code
,t1.ust_code
,t1.dist_entry
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-21 : 00:57:42
it really depends on how tables are related as well. try given suggestion and see if it works. if its not giving you intended results, make sure you post some sample data and also output you want out of them so that we can understand how your tables are related

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -