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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Group from sub query

Author  Topic 

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2013-07-07 : 01:08:18
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)

17689 Posts

Posted - 2013-07-07 : 01:32:44
[code]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[/code]

you can simply do[code]
SELECT c.GSLS, SUM(CAST(CMNS as float)) as CMNS
FROM CS c, TR t
where c.GACCT = t.ACCTNO
GROUP BY c.GLSL[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2013-07-07 : 10:43:51
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
[spoiler]Time is always against us[/spoiler]






Thank you so much !
Go to Top of Page
   

- Advertisement -