August 14, 2006 at 5:49 am
i want to pass datetime to a functon e.g
@startdate,@enddate
the 2 params would look into a table and bring out a column for example "price" for the dates between the 2 dates passed in.
Any ideas?
August 14, 2006 at 5:55 am
There is a topic "CREATE FUNCTION" in BOL.
There are some examples down there.
What's not clear for you in this topic?
_____________
Code for TallyGenerator
August 14, 2006 at 6:50 am
Yeah went through some tutorials.
Will post back if need some help
Thx
August 14, 2006 at 8:58 am
Try this
CREATE FUNCTION TEST_1 (@SDate DateTime,@EDate DateTime)
RETURNS TABLE
AS
RETURN (SELECT price
FROM X
WHERE Convert(Varchar(12),StartDate,112) BetWeen Convert(Varchar(12),@SDate,112)
And Convert(Varchar(12),@EDate,112)
August 14, 2006 at 2:06 pm
Why you need CONVERT?
Just to avoid using index and make this query heavy?
_____________
Code for TallyGenerator
August 14, 2006 at 9:24 pm
Better than that, why do you think you need a function at all? *sniff* *sniff* I smell some RBAR coming up
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply