zimmer9
asked on
Using the SQL Query Analyzer I get the message:GROUP BY expressions must refer to column names that appear in the select list.
Do you know how I can fix the following error:
Server: Msg 164, Level 15, State 1, Line 12
GROUP BY expressions must refer to column names that appear in the select list.
Line 12 is as follows:
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
SELECT tblMthRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe r,
Sum(isnull(MarketValue,0)+ isnull(Cas hBalance,0 )) AS AcctValue,
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()) AS DFrom,
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE()))
AS DateFromC, tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT EADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE())) AS DateToC
FROM tblMthRanges, tblCustomers INNER JOIN tblProducts ON tblCustomers.CustomerNumbe r=tblProdu cts.Custom erNumber
WHERE (((DATEDIFF(M, [DateLost], DATEADD(DD, (DATEPART(DD, GETDATE()) -1) * -1, GETDATE())) >= [MthFrom])) AND
((DateDiff(M,[DateLost],DA TEADD(DD, (DATEPART(DD, GETDATE()) -1) * -1, GETDATE())) < [MthTo])))
GROUP BY tblRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe r,
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE())),
tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT EADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()))
Server: Msg 164, Level 15, State 1, Line 12
GROUP BY expressions must refer to column names that appear in the select list.
Line 12 is as follows:
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
SELECT tblMthRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe
Sum(isnull(MarketValue,0)+
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()) AS DFrom,
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE()))
AS DateFromC, tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT
FROM tblMthRanges, tblCustomers INNER JOIN tblProducts ON tblCustomers.CustomerNumbe
WHERE (((DATEDIFF(M, [DateLost], DATEADD(DD, (DATEPART(DD, GETDATE()) -1) * -1, GETDATE())) >= [MthFrom])) AND
((DateDiff(M,[DateLost],DA
GROUP BY tblRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE())),
tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT
You just have to add the column it's talking about, I assume what you said, the Dateadd function to the select list.
ASKER
The error on line 12 is the 2nd line below in the GROUP BY clause (which I will display again below)
and is reflected in the SELECT list on the 3rd line "AS DFrom":
SELECT tblMthRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe r,
Sum(isnull(MarketValue,0)+ isnull(Cas hBalance,0 )) AS AcctValue,
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()) AS DFrom,
GROUP BY tblRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe r,
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE())),
tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT EADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()))
and is reflected in the SELECT list on the 3rd line "AS DFrom":
SELECT tblMthRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe
Sum(isnull(MarketValue,0)+
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()) AS DFrom,
GROUP BY tblRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE())),
tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT
ASKER
correction:
The error on line 12 is the 2nd line below in the GROUP BY clause (which I will display again below)
and is reflected in the SELECT list on the 3rd line "AS DFrom":
SELECT tblMthRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe r,
Sum(isnull(MarketValue,0)+ isnull(Cas hBalance,0 )) AS AcctValue,
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()) AS DFrom,
GROUP BY tbMthlRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe r,
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE())),
tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT EADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()))
The error on line 12 is the 2nd line below in the GROUP BY clause (which I will display again below)
and is reflected in the SELECT list on the 3rd line "AS DFrom":
SELECT tblMthRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe
Sum(isnull(MarketValue,0)+
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()) AS DFrom,
GROUP BY tbMthlRanges.MthFrom, tblMthRanges.MthTitle, tblCustomers.CustomerNumbe
DATEADD(DD, DATEPART(DD, GETDATE()) * -1, GETDATE()),
DATEADD(M, [MthTo] * -1, DATEADD(DD, (DATEPART(DD, GETDATE()) - 1) * -1, GETDATE())),
tblMthRanges.MthTo,
DATEADD(M,[MthFrom]*-1,DAT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.