Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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
8781 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

549 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  
 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.03 seconds. Powered By: Snitz Forums 2000