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 2005 Forums
 Transact-SQL (2005)
 Outputs from Query

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2009-06-03 : 08:02:04
With this query in brackets, which runs fine, why can't I select from it? Selecting it's output fields or selecting * from it, why do I get "Msg 102, Level 15, State 1, Line 10
Incorrect syntax near ')'.
"

I want to integrate these outputs into another, bigger query.

(select cp.CNPDateCreated, count(cp.CNPDateCreated)
from asdandat.dbo.tbl_centre c
INNER JOIN asdandat.dbo.tbl_net_centre nc ON c.centre_id = nc.centre_ID
inner join asdandat.dbo.tbl_candidates can on can.canCentreID = nc.Centre_ID
inner join asdandat.dbo.tbl_candidatesprogrammes cp on can.CANCandidateID = cp.CNPCandidateID
inner join asdandat.dbo.tbl_programmes p on p.PRGProgrammeCode = cp.CNPProgrammeCode
where c.Reg_Status = 'R'
group by cp.CNPDateCreated
having count(cp.CNPDateCreated)>5)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-03 : 08:46:58
use alias at the end


(select cp.CNPDateCreated, count(cp.CNPDateCreated)
from asdandat.dbo.tbl_centre c
INNER JOIN asdandat.dbo.tbl_net_centre nc ON c.centre_id = nc.centre_ID
inner join asdandat.dbo.tbl_candidates can on can.canCentreID = nc.Centre_ID
inner join asdandat.dbo.tbl_candidatesprogrammes cp on can.CANCandidateID = cp.CNPCandidateID
inner join asdandat.dbo.tbl_programmes p on p.PRGProgrammeCode = cp.CNPProgrammeCode
where c.Reg_Status = 'R'
group by cp.CNPDateCreated
having count(cp.CNPDateCreated)>5) as t


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -