| Author |
Topic |
|
tclose
Starting Member
24 Posts |
Posted - 2010-04-28 : 02:27:48
|
| I'm trying to get the results to group according to the first 2 numbers of the account. Any suggestions.SELECT Account,Description,Product,Balance FROM AssetsWHERE Balance IS NOT NULL UNIONSELECT Account,Description,Product,Balance FROM LiabilitiesWHERE Balance IS NOT NULLUNIONSELECT Account,Description,Product,Balance FROM ExpensesWHERE Balance IS NOT NULLORDER BY Account ON LEFT(Account,2) <-----error |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2010-04-28 : 02:37:58
|
| instead of ORDER BY Account ON LEFT(Account,2) <-----erroruse only ORDER BY LEFT(Account,2)Karthikhttp://karthik4identity.blogspot.com/ |
 |
|
|
tclose
Starting Member
24 Posts |
Posted - 2010-04-28 : 02:54:52
|
quote: Originally posted by karthik_padbanaban instead of ORDER BY Account ON LEFT(Account,2) <-----erroruse only ORDER BY LEFT(Account,2)Karthikhttp://karthik4identity.blogspot.com/
Thanks for responding. When I do that I get the following error:ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator. |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2010-04-28 : 03:05:07
|
quote: Originally posted by tclose
quote: Originally posted by karthik_padbanaban instead of ORDER BY Account ON LEFT(Account,2) <-----erroruse only ORDER BY LEFT(Account,2)Karthikhttp://karthik4identity.blogspot.com/
Thanks for responding. When I do that I get the following error:ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.
--- dont use first columnSELECT left(Account,2),Account,Description,Product,Balance FROM AssetsWHERE Balance IS NOT NULL UNIONSELECT left(Account,2),Account,Description,Product,Balance FROM LiabilitiesWHERE Balance IS NOT NULLUNIONSELECT left(Account,2),Account,Description,Product,Balance FROM ExpensesWHERE Balance IS NOT NULLORDER BY left(Account,2)Karthikhttp://karthik4identity.blogspot.com/ |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2010-04-28 : 03:07:45
|
| or you can use in this wayselect Account,Description,Product,Balance FROM(SELECT Account,Description,Product,Balance FROM AssetsWHERE Balance IS NOT NULL UNIONSELECT Account,Description,Product,Balance FROM LiabilitiesWHERE Balance IS NOT NULLUNIONSELECT Account,Description,Product,Balance FROM ExpensesWHERE Balance IS NOT NULL)as a ORDER BY left(a.Account,2)Karthikhttp://karthik4identity.blogspot.com/ |
 |
|
|
tclose
Starting Member
24 Posts |
Posted - 2010-04-28 : 03:13:10
|
quote: Originally posted by karthik_padbanaban or you can use in this wayselect Account,Description,Product,Balance FROM(SELECT Account,Description,Product,Balance FROM AssetsWHERE Balance IS NOT NULL UNIONSELECT Account,Description,Product,Balance FROM LiabilitiesWHERE Balance IS NOT NULLUNIONSELECT Account,Description,Product,Balance FROM ExpensesWHERE Balance IS NOT NULL)as a ORDER BY left(a.Account,2)Karthikhttp://karthik4identity.blogspot.com/
Thank you very much - that works great. |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2010-04-28 : 03:15:57
|
Welcome. Karthikhttp://karthik4identity.blogspot.com/ |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-04-28 : 09:53:58
|
You can use it like this also - SELECT left(Account,2),Account,Description,Product,Balance FROM AssetsWHERE Balance IS NOT NULL UNIONSELECT left(Account,2),Account,Description,Product,Balance FROM LiabilitiesWHERE Balance IS NOT NULLUNIONSELECT left(Account,2),Account,Description,Product,Balance FROM ExpensesWHERE Balance IS NOT NULLORDER BY 1 Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
|
|
|
|