|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
MS SQL Error Message
When I run this query I get an error message:
select Col1, Col2, (convert(decimal(12,2),Col2)/convert(decimal(12,2),Col1))*100 as Col3 from (select top 100 percent count(col)as Col1,(select count(col) from table where substring(col,6,2) > 49 and substring(col,6,2) < 100) as Col2 from table order by substring(col,1,4) --group by col ) as mytable Error message: Server: Msg 8118, Level 16, State 1, Line 1 Column 'table.col' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause. I have tried adding the missing column everywhere and I am still getting this error message. I don't know what else to do. Please help. |
|
#2
|
||||
|
||||
|
let's look at your query, but first, let's re-write it so that it's somewhat easier to read --
Code:
select Col1
, Col2
, (convert(decimal(12,2),Col2)
/convert(decimal(12,2),Col1))*100 as Col3
from (
select top 100 percent
count(col)as Col1
, (select count(col)
from table
where substring(col,6,2) > 49
and substring(col,6,2) < 100) as Col2
from table
order
by substring(col,1,4)
--group by col
) as mytable
now look at the nested query you are returning the "top 100 percent" of what should be a single row, a row containing two numbers therefore, to try to sort this single row by a substring makes no sense |
|
#3
|
|||
|
|||
|
MS SQL Error Message Post 2575
I have tried to use order by without using top and I was getting this error message:
The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified. Can you give me the work around? How else can I sort this query? |
|
#4
|
||||
|
||||
|
why do you want to sort one row??????
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > MS SQL Error Message |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|