Discussion Locked

SQL Nested Queries

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi...

I am trying to do a SQL nested query where like following:

Select * FROM (SELECT TOP 23 PERCENT convert(varchar,cast(dateCommInstalled as datetime),10) AS dateCommInstalled, COUNT(retNum) AS countofretnum, Row_Number() Over (order by dateCommInstalled ASC) as row FROM TABLE1 BY dateCommInstalled HAVING (dateCommInstalled IS NOT NULL) ORDER BY cast(dateCommInstalled as datetime)) order by datecomminstalled DESC

But, SQL (2005) does like this sort of nested query. What I trying to do is basically get a set of results, sorted in DESC order, then reverse the order.

Any help is appreciated.

Dan

2 replies

by john.a.wills

If you want to get the result of reversing a DESC sort, why not do an ASC sort in the first place.

Your code as shown is not very enlightening.

by tony hopkinson

Select * from (..nested..) dummytable Where ...

Doesn't matter what dummytable is as long as it's a valid table name. It not being there is something the parser won't cope with.

This discussion is closed to new replies.