|
-
Jul 13th, 2009, 01:26 AM
#1
Thread Starter
Hyperactive Member
SQL Queries :Using Computed Columns as Filter
am trying to use a computed column in filter clause of an SQL query but its giving me errors, i guess its either not possible or am not doing it correctly. Any SQL guru 4 help?
(just a sample below)
select DisTable.*,s_name,fun_count(x_items) as myItems
from DisTable,UserTable
where DisTable.Name=s_name
and myItems > 0
Nobody is smarter than all of us!
-
Jul 13th, 2009, 03:34 AM
#2
Re: SQL Queries :Using Computed Columns as Filter
Use HAVING Clause.
sql Code:
select DisTable.*,s_name,fun_count(x_items) as myItems from DisTable,UserTable where DisTable.Name=s_name GROUP BY DisTable.*,s_name --instead of *, you need to mention each column separately HAVING myItems > 0
The only glitch is if you have way too many columns, adding them to Group by clause could be cumbersome.
If fun_count() is user-defined function, another (possible) way could be that you can let it return records based on the conditions you want to put here. E.g. In your example, let it send you all records which will be greater than 0. Just a guess though. I don't know how this function looks like.
-
Jul 13th, 2009, 04:05 AM
#3
Thread Starter
Hyperactive Member
Re: SQL Queries :Using Computed Columns as Filter
 Originally Posted by Harsh Gupta
Use HAVING Clause.
sql Code:
select DisTable.*,s_name,fun_count(x_items) as myItems
from DisTable,UserTable
where DisTable.Name=s_name
GROUP BY DisTable.*,s_name --instead of *, you need to mention each column separately
HAVING myItems > 0
The only glitch is if you have way too many columns, adding them to Group by clause could be cumbersome.
If fun_count() is user-defined function, another (possible) way could be that you can let it return records based on the conditions you want to put here. E.g. In your example, let it send you all records which will be greater than 0. Just a guess though. I don't know how this function looks like.
from your sample, i get error on line 5, myItems is an invalid identifier
Nobody is smarter than all of us!
-
Jul 13th, 2009, 04:29 AM
#4
Re: SQL Queries :Using Computed Columns as Filter
Sorry for the typo. You cannot use alias names. It should be this:
Code:
HAVING fun_count(x_items) > 0
-
Jul 13th, 2009, 05:57 AM
#5
Re: SQL Queries :Using Computed Columns as Filter
Moved To Database Development
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|