Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
morteza
Starting Member
1 Post |
Posted - 2008-12-28 : 02:52:39
|
Dear alli am writing this code to select first the maxmimun QTY from PUBS dband then select the minimum one of this nested slect :select a.min(qty),stor_id,ord_num,ord_date,payterms,title_idfrom sales as s inner join(select max(qty),title_id from sales group by title_id)as aon s.title_id=a.title_idgroup by stor_id,ord_num,ord_date,payterms,title_idwhen i run this code i got this error:Server: Msg 8155, Level 16, State 2, Line 1No column was specified for column 1 of 'a'.please help me and tell me that what shoud i do? |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2008-12-28 : 09:30:20
|
You need to alias the calculated column inside the subquery. In a subquery, all returned columns must have defined names. If there's a function used as a column, that means you need to alias it.Also, the a.min in the outer select should be min(a.qty)So...select min(a.qty),stor_id,ord_num,ord_date,payterms,title_idfrom sales as s inner join(select max(qty) AS qty,title_id from sales group by title_id)as aon s.title_id=a.title_idgroup by stor_id,ord_num,ord_date,payterms,title_id--Gail ShawSQL Server MVP |
|
|
X002548
Not Just a Number
15586 Posts |
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2008-12-28 : 23:15:57
|
Do Just That...your query.....Min(A.Qty),,,,your rest query |
|
|
|
|
|
|
|