HNA071252
asked on
sql server 2005 - select count
How do you do select count from a select statement?
How do I write a select statement that would return a number or record from this select statement?
SELECT 'Check 2' as Check_point_2, Par_id, Trend_type, TypeOfContract, PlanEffDt
FROM TRP.FFS_Contracts
GROUP BY Par_id, Trend_type, TypeOfContract, PlanEffDt
HAVING count(Par_id) > 1
How do I write a select statement that would return a number or record from this select statement?
SELECT 'Check 2' as Check_point_2, Par_id, Trend_type, TypeOfContract, PlanEffDt
FROM TRP.FFS_Contracts
GROUP BY Par_id, Trend_type, TypeOfContract, PlanEffDt
HAVING count(Par_id) > 1
select count x.* from
(SELECT 'Check 2' as Check_point_2, Par_id, Trend_type, TypeOfContract, PlanEffDt
FROM TRP.FFS_Contracts
GROUP BY Par_id, Trend_type, TypeOfContract, PlanEffDt
HAVING count(Par_id) > 1) x
(SELECT 'Check 2' as Check_point_2, Par_id, Trend_type, TypeOfContract, PlanEffDt
FROM TRP.FFS_Contracts
GROUP BY Par_id, Trend_type, TypeOfContract, PlanEffDt
HAVING count(Par_id) > 1) x
ASKER
Can you please double check? got this syntax error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '*'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'x'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '*'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'x'.
Weird. I'll have a look.
Here you go, sorry 'bout that:
select COUNT(*) from
(SELECT 'Check 2' as Check_point_2, Par_id, Trend_type, TypeOfContract, PlanEffDt
FROM TRP.FFS_Contracts
GROUP BY Par_id, Trend_type, TypeOfContract, PlanEffDt
HAVING count(Par_id) > 1)
select COUNT(*) from
(SELECT 'Check 2' as Check_point_2, Par_id, Trend_type, TypeOfContract, PlanEffDt
FROM TRP.FFS_Contracts
GROUP BY Par_id, Trend_type, TypeOfContract, PlanEffDt
HAVING count(Par_id) > 1)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
ASKER