eo
MIS
- Apr 3, 2003
- 809
Hi,
I am writing a function. The function is based on a single table with 10 datetime columns. Lets call then DataTime1, DateTime2, ..., DateTime10.
The user will decide at runtime which Column to return, so I thought of parameterising the function to allow the user to select between DateTime1, ..., DateTime10 at runtime, and that will then return the corresponding Column. The actual function does all sorts of stuff, so this is simply a very simplistic view thereof, but you will get the idea.
...The problem is that when the query is run...
...then the Actual string is passed and I do not see...
DateTime4 (the actual datetime values), FieldA, FieldB, FieldC
...as expected
Is there anyway this can be done, otherwise I have to write 10 seperate functions, one for each possible option, and that just seems like a real waste
EO
Hertfordshire, England
I am writing a function. The function is based on a single table with 10 datetime columns. Lets call then DataTime1, DateTime2, ..., DateTime10.
The user will decide at runtime which Column to return, so I thought of parameterising the function to allow the user to select between DateTime1, ..., DateTime10 at runtime, and that will then return the corresponding Column. The actual function does all sorts of stuff, so this is simply a very simplistic view thereof, but you will get the idea.
Code:
ALTER FUNCTION [dbo].[fn_selectADateAndSomeFields]
(@SelectDate nvarchar(15))
RETURNS TABLE
AS
RETURN
SELECT @SelectDate, FieldA, FieldB, FieldC
FROM dbo.Table
ORDER BY @SelectDate Desc
GO
...The problem is that when the query is run...
Code:
select * from [dbo].[fn_selectADateAndSomeFields] ('DateTime4')
...then the Actual string is passed and I do not see...
DateTime4 (the actual datetime values), FieldA, FieldB, FieldC
...as expected
Is there anyway this can be done, otherwise I have to write 10 seperate functions, one for each possible option, and that just seems like a real waste
EO
Hertfordshire, England