SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Group By
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

divan
Posting Yak Master

153 Posts

Posted - 05/16/2013 :  09:21:10  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 05/16/2013 :  09:31:32  Show Profile  Visit webfred's Homepage  Reply with Quote
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

547 Posts

Posted - 05/16/2013 :  10:28:35  Show Profile  Reply with Quote
Or you can try this:


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
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 05/16/2013 :  10:49:05  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000