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.
| Author |
Topic |
|
sqlnovice123
Constraint Violating Yak Guru
262 Posts |
Posted - 2010-02-25 : 13:51:08
|
| Hi,I get this error when i try to insert a column in a temp table:Column '#Trade.Product' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.When I add the trd.Product column to the Group By clause, I get anotehr error. But if I use ProductID instead I get the results. i want to be able to see the Product. Is this because the Product is a non numeric and I cannot group by the column? What am I missing?ThanksSELECT InquiryDate = inq.InquiryDate, InquiryID = inq.SystemInquiryID, Client = cli.Company_Name, CPLevel = MAX(trd.CPLevel), DealerCount = COUNT(DISTINCT res.CPPivotalCompanyID), ResponseCount = COUNT(DISTINCT CASE WHEN rsl.CPLevel IS NOT NULL THEN res.CPPivotalCompanyID END), ExecutedDealer = MAX(CASE WHEN rsl.State = 'T' THEN REPLACE(dlr.Short_Name_1, '_US', '') END), ExecutedPrice = MAX(CASE WHEN rsl.State = 'T' THEN rsl.Price END), ExecutedLevel = MAX(CASE WHEN rsl.State = 'T' THEN rsl.CPLevel END), CoverLevel = MAX(CASE WHEN rsl.State = 'C' THEN rsl.CPLevel END), CoverDealer = MAX(CASE WHEN rsl.State = 'C' THEN REPLACE(dlr.Short_Name_1, '_US', '') END), TradeYear = trd.TradeYear, TradeMonthName = trd.TradeMonthName, TradeMonth = trd.TradeMonth, Product = trd.Product INTO #ResponseFROM #Trade trdINNER JOIN Inquiry inqON trd.MISInquiryID = inq.MISInquiryIDINNER JOIN InquiryLeg iqlON inq.MISInquiryID = iql.MISInquiryIDINNER JOIN Response resON res.MISInquiryID = iql.MISInquiryIDINNER JOIN ResponseLeg rslON res.MISResponseID = rsl.MISResponseIDand iql.MISInquiryID = rsl.MISInquiryIDand iql.LegSequence = rsl.LegSequenceINNER JOIN pivotal..Company dlrON res.CPPivotalCompanyID = dlr.Company_IdINNER JOIN pivotal..Company cliON trd.ClientID = cli.Company_IdWHERE inq.IsVolume = 1and iql.IsVolume = 1and InquiryType = 'F'GROUP BY trd.TradeYear, trd.TradeMonth, trd.TradeMonthName, cli.Company_Name, inq.InquiryDate, inq.SystemInquiryID |
|
|
sqlnovice123
Constraint Violating Yak Guru
262 Posts |
Posted - 2010-02-25 : 13:53:56
|
| Never mind. I got it. just selected trd.Product and grouped by trd.Product since the Product already exists in the temp table #Trade. |
 |
|
|
|
|
|
|
|