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 2005 Forums
 Transact-SQL (2005)
 Query help

Author  Topic 

DaveC11
Starting Member

43 Posts

Posted - 2008-06-04 : 06:03:31
I get the this error message when I try and run this, can anyone help?

error -
Msg 207, Level 16, State 1, Line 25
Invalid column name 'username'.
Msg 207, Level 16, State 1, Line 25
Invalid column name 'surname'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'username'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'surname'.



select
username + ' ' + surname,
DATENAME(MONTH, createdon) AS theMonth,
sum(CASE WHEN RowNo=1 THEN placementfee ELSE 0 END) as 'Amount Boarded',
count(distinct placementid) 'Number of Deals'
,SUM(netsum) as 'Amount Invoiced',
SUM(CASE WHEN RowNo=1 THEN placementfee ELSE 0 END)- SUM(netsum)as 'Waiting to invoice'
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY p.placementid ORDER BY i.invoiceid) AS RowNo,p.createdon,p.placementfee,p.placementid,i.netsum
FROM placements p
join placementconsultants pc on pc.placementid = p.placementid
join users u on u.userid = pc.userid
left outer join placementinvoices pp on pp.placementid = p.placementid
left join invoices i on i.invoiceid = pp.invoiceid

WHERE p.createdon >= '20080101'
AND p.createdon < '20150101'
AND p.createdon < '20150101' and p.placementtypeid not in('6','5','17','19','23','26')

)tmp

GROUP BY DATENAME(MONTH, tmp.createdon),
DATEPART(MONTH, tmp.createdon),tmp.username + ' ' + tmp.surname

ORDER BY DATEPART(MONTH, tmp.createdon)



harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-06-04 : 06:07:00
I don't see those columns in the derived table.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-06-04 : 06:07:42
derived table tmp should include the username and surname in the select list.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-04 : 06:13:38
Include surname,username,...fields in SELECT list of tmp
Go to Top of Page
   

- Advertisement -