I'm new here so go easy on me. How do I pass a column value as a function parameter?
I have this query to select months and years:
SELECT
DATEPART(MONTH, a.RequestDate),
DATEPART(YEAR, a.RequestDate)
FROM
TABLE A
Sample data:
Months Years
------ -----
5 2013
3 2013
1 2013
9 2013
The values are not in order and could be duplicates.
I want to pass these value one by one to a function parameter automatically:
SELECT WeekNo
FROM _GLOBALDB.dbo.fn_WeekNoListInMonth(a.Months, a.Years)
The result would show what weeks would be in that particular month. For example:
SELECT MIN(WeekNo)
FROM fn_WeekNoListInMonth(5, 2013)
Expected result:
WeekNO
------
18
19
20
21
I've tried this:
SELECT MIN(WeekNo)
FROM fn_WeekNoListInMonth(A.Months, A.Years)
But it shows an error:
The multi-part identifier "A.Months" could not be bound.
The multi-part identifier "t.Months" could not be bound.
fn_WeekNoListInMonth()for each row inA? So, if there were 10 rows in A, you'd get between 40 and 50 rows back? Or do you need to get the lowest value from the output of the function, for each row in 'A'?MINin the question, if you weren't trying to get the top or bottom value?)