Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,355 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,139 people online right now. Registration is fast and FREE... Join Now!




Help with t-sql dateadd SP

 
Reply to this topicStart new topic

Help with t-sql dateadd SP

RudyVB.net
post 25 Aug, 2008 - 07:17 PM
Post #1


D.I.C Head

**
Joined: 3 May, 2008
Posts: 61

Hello All!

I almost got this, I think. I'm trying to get the current time, add a minute to it, then add it to the tblschedule. How would I write this correctly?

Thanks!

Rudy

CODE
-- =============================================
ALTER PROCEDURE [dbo].[updScheduleSet]
    -- Add the parameters for the stored procedure here
    @InmID int,
@VisID int,
--@Date nchar(10),
--@Time nchar(10),
@RealDate datetime,
@VisInfoId int,
@InmInfoId int,
@MAXID int OUTPUT



AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
SET @RealDate =   (SELECT DATEADD(minute, 1, {fn NOW()}) )


    INSERT INTO tblSchedule
                      (InmID, VisID, Realdate,  VisInfoID, InmInfoID)
VALUES     (@InmId,@VisId, @RealDate, @VisInfoID, @InmInfoID)



SELECT @MaxID = max (SchedID)
FROM tblSchedule


END
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 25 Aug, 2008 - 09:05 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,027



Thanked 173 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


What errors are you getting? Here is an example of taking the time, adding a minute and inserting it into a table called testschedule...

CODE

CREATE PROCEDURE [dbo].[addscheduledate] AS

-- Declare our variable as a datetime
DECLARE @RealDate datetime

BEGIN

-- Set NOCOUNT on and then select the date, adding 1 minute
SET NOCOUNT ON;
SET @RealDate =   (SELECT DATEADD(minute,1, {fn NOW()}) )

-- Now take that variable and put it into an INSERT statement into the table.
-- Here "thedate" represents a datetime column.

INSERT INTO testschedule (thedate)  VALUES  (@RealDate)

END
GO


We create a datetime variable, take the current time and add 1 minute, then insert it into our table called testschedule. The column "thedate" is of type datetime and notice we insert it in.

Make sure that if your column InmID is the primary key and set as identity to autoincrement that you DO NOT include it in the insert query.

Hope this works out for you. Enjoy!

"At DIC we be TSQL kicking code ninjas... we also kick ASP, TNA, RPG, NWA, and OMFGLOL!" decap.gif
User is offlineProfile CardPM

Go to the top of the page

RudyVB.net
post 26 Aug, 2008 - 03:54 AM
Post #3


D.I.C Head

**
Joined: 3 May, 2008
Posts: 61

Hi Maryr2!

So when I have this,
CODE
INSERT INTO tblSchedule
                      (InmID, VisID, Realdate,  VisInfoID, InmInfoID)
VALUES     (@InmId,@VisId, @RealDate, @VisInfoID, @InmInfoID)

When I run the SP, it says I need to add the value for @RealDate. But I shouldn't have to if I have

CODE
SET @RealDate =   (SELECT DATEADD(minute, 1, {fn NOW()}) )

Now the other values will come from my program. I don't notice anything different that you did, that I didn't do.

Maybe the result of late night programing. I have a deadline and it's crunch time.

I'll give it another go this morning and let you know.

Thanks!!

Rudy
User is offlineProfile CardPM

Go to the top of the page

RudyVB.net
post 26 Aug, 2008 - 04:41 AM
Post #4


D.I.C Head

**
Joined: 3 May, 2008
Posts: 61

QUOTE(RudyVB.net @ 26 Aug, 2008 - 04:54 AM) *

Hi Maryr2!

So when I have this,
CODE
INSERT INTO tblSchedule
                      (InmID, VisID, Realdate,  VisInfoID, InmInfoID)
VALUES     (@InmId,@VisId, @RealDate, @VisInfoID, @InmInfoID)

When I run the SP, it says I need to add the value for @RealDate. But I shouldn't have to if I have

CODE
SET @RealDate =   (SELECT DATEADD(minute, 1, {fn NOW()}) )

Now the other values will come from my program. I don't notice anything different that you did, that I didn't do.

Maybe the result of late night programing. I have a deadline and it's crunch time.

I'll give it another go this morning and let you know.

Thanks!!

OK! I got it! My mistake. When I declared @RealDate, I did not =to NULL
@RealDate datetime = NULL

Thanks!

Rudy

Rudy

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 04:08AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month