Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a use function in a group by

Status
Not open for further replies.

junkmail

Programmer
Jan 7, 2001
134
US
I have a function that I wrote to return a tax rate for a list of records but I want to be able to sum by the return tax rate but I get the following error "Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause
 
get_tax_rate" is the function I wrote to get the tax rate.

SELECT (select * from get_tax_rate([ship city],[ship state])) as [Tax Rate],
sum(Cost) as cost,sum([Final Ship Cost]) as [ship cost],
sum([misc cost]) as delivery,[ship city],[ship state],
FROM orders
where exists (select item from tandem_items where item=[product name] ) and
([ship date]>=@stdate and [ship date]<=@enddate)

group by (select * from get_tax_rate([ship city],[ship state]))
 
The problem is I need to group by the tax rate which is derived from passing those two values to the function.
 
What columns do you want in your final output?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks for your suggestions but I was able to use a temporary table and get the proper results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top