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
 Group By

Author  Topic 

divan
Posting Yak Master

153 Posts

Posted - 2013-05-16 : 09:21:10
I have the following script statement

Select ltrim(isnull(c1.fname1,''), + isnull(c1.init1,''), + isnull(c1.lname1) as physician, sum (m.premium) as Total_premium
from mntable
group by Physician

When I run the script I get the following error
Invalid column name..

How can I group the result by Physician even though Physcian is not a column in the table..

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-05-16 : 09:31:32
repeat your concatenation in group by


Too old to Rock'n'Roll too young to die.
Go to Top of Page

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-05-16 : 10:28:35
Or you can try this:

[CODE]
SELECT physician, SUM(premium) as Total_premium from
(Select ltrim(isnull(c1.fname1,''), + isnull(c1.init1,''), + isnull(c1.lname1) as physician,
m.premium from mntable) MN GROUP BY physician
[/CODE]
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-16 : 10:49:05
Select ltrim(isnull(c1.fname1,''))+',' + isnull(c1.init1,'')+',' + isnull(c1.lname1) as physician, sum (m.premium) as Total_premium
from mntable
group by ltrim(isnull(c1.fname1,''))+','+isnull(c1.init1,'')+','+isnull(c1.lname1)

Cheers
MIK
Go to Top of Page
   

- Advertisement -