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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Group from sub query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dbonneau
Yak Posting Veteran

50 Posts

Posted - 07/07/2013 :  01:08:18  Show Profile  Reply with Quote
Hi, I am trying to group by "GSLS" column from the data set from sub-query, but I get error saying Incorrect syntax near N. Could you tell me why this is wrong ? Thank you so much !

SELECT GSLS, sum(CMNS) as CMNS

( SELECT c.GSLS, CAST(CMNS as float) as CMNS    
	FROM CS c,  TR t
		where c.GACCT = t.ACCTNO) N

Group by GSLS

khtan
In (Som, Ni, Yak)

Singapore
17595 Posts

Posted - 07/07/2013 :  01:32:44  Show Profile  Reply with Quote
SELECT GSLS, sum(CMNS) as CMNS
FROM
( SELECT c.GSLS, CAST(CMNS as float) as CMNS    
	FROM CS c,  TR t
		where c.GACCT = t.ACCTNO) N

Group by GSLS


you can simply do

SELECT c.GSLS, SUM(CAST(CMNS as float)) as CMNS    
FROM   CS c,  TR t
where  c.GACCT = t.ACCTNO
GROUP BY c.GLSL



KH
Time is always against us

Go to Top of Page

dbonneau
Yak Posting Veteran

50 Posts

Posted - 07/07/2013 :  10:43:51  Show Profile  Reply with Quote
quote:
Originally posted by khtan

SELECT GSLS, sum(CMNS) as CMNS
FROM
( SELECT c.GSLS, CAST(CMNS as float) as CMNS    
	FROM CS c,  TR t
		where c.GACCT = t.ACCTNO) N

Group by GSLS


you can simply do

SELECT c.GSLS, SUM(CAST(CMNS as float)) as CMNS    
FROM   CS c,  TR t
where  c.GACCT = t.ACCTNO
GROUP BY c.GLSL



KH
Time is always against us






Thank you so much !
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.06 seconds. Powered By: Snitz Forums 2000