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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Invalid Column Name? Confusion ensues...

Author  Topic 

Glendale
Starting Member

5 Posts

Posted - 2008-01-28 : 12:16:32
The SQL statement:

CREATE TABLE #DonationsThisYear
(Solicitor nvarchar(8), SumPayment bigint, CountPayment int)
INSERT INTO #DonationsThisYear

SELECT
FamilyDonationHistory.Solicitor AS Solicitor,
SUM(FamilyDonationHistory.PaymentAmt) AS SumPayment,
COUNT(FamilyDonationHistory.PaymentAmt) AS CountPayment
FROM
FamilyDonationHistory
WHERE
(DepositDate < @today)
AND ((right(Event, 2)) = right(@year, 2))
AND (left(Event, 2) <> 'TR')
GROUP BY
Solicitor,
SumPayment,
CountPayment

The errors:

Server: Msg 207, Level 16, State 3, Line 3
Invalid column name 'SumPayment'.
Server: Msg 207, Level 16, State 1, Line 3
Invalid column name 'CountPayment'.
Server: Msg 207, Level 16, State 1, Line 3
Invalid column name 'SumPayment'.
Server: Msg 207, Level 16, State 1, Line 3
Invalid column name 'CountPayment'.

What's the deal? I don't see what the problem is here...

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-28 : 12:20:36
GROUP BY
Solicitor
,
SumPayment,
CountPayment




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-28 : 12:22:21
You will not succeed with grouping by the aggregated value
CREATE TABLE	#DonationsThisYear
(
Solicitor nvarchar(8),
SumPayment bigint,
CountPayment int
)

INSERT INTO #DonationsThisYear
(
Solicitor,
SumPayment
CountPayment
)
SELECT Solicitor,
SUM(PaymentAmt) AS SumPayment,
COUNT(PaymentAmt) AS CountPayment
FROM FamilyDonationHistory
WHERE DepositDate < @Today
AND RIGHT(Event, 2)) = RIGHT(@Year, 2)
AND LEFT(Event, 2) <> 'TR'
GROUP BY Solicitor



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Glendale
Starting Member

5 Posts

Posted - 2008-01-28 : 12:34:42
Oh yes, I think I understand... I can't group based on the aggregate value because there will only ever be one record returned for each Solicitor, right?

Either way, your solution worked.
Thanks for the help..
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-29 : 02:10:28
You are correct and you're welcome!



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -