[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • Last Modified:

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
0
HNA071252
Asked:
HNA071252
  • 4
  • 3
1 Solution
 
HNA071252Author Commented:
I.e, If the above select statement return 5 records then it would give me a 5, or 0 if the above select statement return no record.
0
 
Simone BCommented:
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
0
 
HNA071252Author Commented:
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'.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
Simone BCommented:
Weird. I'll have a look.
0
 
Simone BCommented:
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)
0
 
Simone BCommented:
Good grief, once more for luck:

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)  x
0
 
HNA071252Author Commented:
Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now