0

I want to select the columns TeamProjectProjectNodeName & TestPlanName from the inner subquery. The inner query runs perfectly fine in fetching results from the view. But I am getting the below error, when I run the entire query as below -

Incorrect syntax near ')'.

Please help me with the same.

Here is my query -

select 
    x.TeamProjectProjectNodeName, x.TestPlanName
from 
    (select 
         TeamProjectProjectNodeName, TestPlanName,ResultOutcome, count(ResultOutcome) 
     from [Tfs_Warehouse].[dbo].[TestResultView] 
     where TestPlanName <> 'NULL'
     GROUP BY TeamProjectProjectNodeName, TestPlanName, ResultOutcome
     order by TeamProjectProjectNodeName asc, TestPlanName asc) x

Thanks.

3
  • 1
    A few questions, if you run the subquery on its own does it run? In the existing query, remove the order by from the subquery and place an alias on the count(). Do you mean to use <> null or do you want is not null? Commented Jun 4, 2013 at 15:06
  • What data type is ResultOutcome? Commented Jun 4, 2013 at 15:14
  • ResultOutcome is varchar Commented Jun 4, 2013 at 15:37

3 Answers 3

4

Bring order by out of the sub query, and name the count column like this:

select 
   x.TeamProjectProjectNodeName,
   x.TestPlanName,
   x.Total
from (select 
         TeamProjectProjectNodeName,
         TestPlanName,
         ResultOutcome, 
         count(*) as Total 
      from [Tfs_Warehouse].[dbo].[TestResultView] 
      where TestPlanName IS NOT NULL
      GROUP BY TeamProjectProjectNodeName, TestPlanName, ResultOutcome
     ) x
order by TeamProjectProjectNodeName asc, TestPlanName asc 

I have also changed your WHERE syntax to IS NOT NULL as @bluefeet suggested, as I imagine this is what you actually require.

Sign up to request clarification or add additional context in comments.

1 Comment

I would suggest possibly changing or making a note to change the TestPlanName <> 'NULL' to TestPlanName is not null. If they are really testing for null. The first will not work unless they are actually storing null as a string.
1

Here you go :

select x.TeamProjectProjectNodeName,x.TestPlanName
from (select top 100 percent TeamProjectProjectNodeName,TestPlanName,ResultOutcome, count(ResultOutcome) SomeAlias from [Tfs_Warehouse].[dbo].[TestResultView] 
where TestPlanName <> 'NULL'
GROUP BY TeamProjectProjectNodeName, TestPlanName, ResultOutcome
order by TeamProjectProjectNodeName asc, TestPlanName asc) x

You cannot have a order by in your inner select unless you specify top and the count() should have an alias.

3 Comments

You might want to remove the order by from the subquery. :)
You can use it with a top 100 percent. But is that useful? ;-)
Yeah I have to agree it is horrible practice.
0

I would suggest to give your count() an alias and group by aggregate function to avoid the error

select x.TeamProjectProjectNodeName,x.TestPlanName
from (select TeamProjectProjectNodeName,TestPlanName,ResultOutcome, count(ResultOutcome) as total from [Tfs_Warehouse].[dbo].[TestResultView] 
where TestPlanName <> 'NULL'
GROUP BY TeamProjectProjectNodeName, TestPlanName, ResultOutcome) x

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.