Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

date time function please help

airwalkerairwalker Member Posts: 71
Hi

I have a table called schedule that consists of 2 columns, start_date and end_date. I have entered values into the start_date column, but I need a function that will work out the end data based on parameters:

the start_date and the No of weeks (which is entered by the user). I need the function to be part of a insert function like this

create proc start_end
@start_date smalldatetime, @end_date smalldatetime
AS
BEGIN
INSERT schedule
(start_date, end_date)
VALUES(@start_date, @end_date)
END
GO
EXEC [insert schedule]
@startdate = '07/19/2005'
@end_date = start_date + w (where w = no weeks entered by the user)

Thanks, any suggestions would be greatly appreciated.


Comments

  • sumit_chauhansumit_chauhan Member Posts: 4
    Hi

    I am sorry but i try to resolve it without making any practicle attempt. As i donot have SQL Server right now, the code may not be the most efficient one. So to make it completely functional incorporate your ideas.

    Create Procedure Proc_name
    @StartDate datetime
    As
    begin
    Declare @Enddate datetime
    Set @Enddate = dbo.func_name(@StartDate)
    insert into tblName(@start_date, @enddate)
    end

    //Function defination
    Create function func_name(@star datetime)
    returns nvarchar(10)
    As
    begin
    Declare @dd datetime
    Select @dd = @startdate + add weeks
    return cast(@dd as nvarchar(100)
    end




    : Hi
    :
    : I have a table called schedule that consists of 2 columns, start_date and end_date. I have entered values into the start_date column, but I need a function that will work out the end data based on parameters:
    :
    : the start_date and the No of weeks (which is entered by the user). I need the function to be part of a insert function like this
    :
    : create proc start_end
    : @start_date smalldatetime, @end_date smalldatetime
    : AS
    : BEGIN
    : INSERT schedule
    : (start_date, end_date)
    : VALUES(@start_date, @end_date)
    : END
    : GO
    : EXEC [insert schedule]
    : @startdate = '07/19/2005'
    : @end_date = start_date + w (where w = no weeks entered by the user)
    :
    : Thanks, any suggestions would be greatly appreciated.
    :
    :
    :

Sign In or Register to comment.