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!

How do I put a function within a function?

Status
Not open for further replies.

Tarzan613

Programmer
Jun 10, 2002
10
0
0
US

select month(ord_date),(select daysinmonth(month(ord_date))
from ord
where ord_date>'1/2/02'
group by month(ord_date)

returns this error

Server: Msg 8120, Level 16, State 1, Line 3
Column 'ord.ORD_DATE' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

daysinmonth is a user defined function that returns the number of working days in a month.

 
All columns in the select list must eaither be in the Group By clasue or be part of an aggregate function. You don't need the Select to get the results of the daysinmonthfuncition.

select
Mnth=month(ord_date),
DaysInMnth=daysinmonth(month(ord_date))
from ord
where ord_date>'1/2/02'
group by
month(ord_date),
daysinmonth(month(ord_date)

Alternate: Use an aggregate function
(MAX, MIN, SUM, etc.)

select
Mnth=month(ord_date),
DaysInMnth=MAX(daysinmonth(month(ord_date)))
from ord
where ord_date>'1/2/02'
group by
month(ord_date) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top