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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Group from sub query
 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
17689 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  
 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.04 seconds. Powered By: Snitz Forums 2000