Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Another simple SQL query

I have a query that returns all rows with a single identifier:

select ParentLink_RecId
        from TASK
        --where (RESOLVEDDATETIME) = 2008
        Group by ParentLink_RecId
        having count(ParentLink_RecId) = 1

Now what I want to do is use this as the input in a nested SQL query:

e.g. select count(1)
from (select ParentLink_RecId
        from TASK
        where (RESOLVEDDATETIME) = 2008
        Group by ParentLink_RecId, ownerteam, month(RESOLVEDDATETIME)
        having count(ParentLink_RecId) = 1)
I get a Incorrect syntax near )

I need to only pull relevant data back from the initial result set any ideas?

Any idea's as this should be easy - I essentially just need to loop the input from the initial query bringing back other details
0
Netstore
Asked:
Netstore
1 Solution
 
chapmandewCommented:
needed an alias.

select count(1)
from (select ParentLink_RecId
        from TASK
        where (RESOLVEDDATETIME) = 2008
        Group by ParentLink_RecId, ownerteam, month(RESOLVEDDATETIME)
        having count(ParentLink_RecId) = 1) a
0
 
Kevin CrossChief Technology OfficerCommented:
SELECT COUNT(*)
FROM
(
select ParentLink_RecId
from TASK
where (RESOLVEDDATETIME) = 2008
Group by ParentLink_RecId
having count(ParentLink_RecId) = 1
) derived
0
 
Kevin CrossChief Technology OfficerCommented:
Like Tim said!  Needs an alias.
0
 
Cedric_DCommented:
correct syntax is:

select count(1)
from (select ParentLink_RecId
        from TASK
        where (RESOLVEDDATETIME) = 2008
        Group by ParentLink_RecId, ownerteam, month(RESOLVEDDATETIME)
        having count(ParentLink_RecId) = 1
) as a     -- <<<<<<<<<<<<<<<<<<<<<
0
 
NetstoreAuthor Commented:
Top cheers - so close yet so far 8)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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