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

Join 136,413 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,426 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
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
+Quote Post

Martyr2
RE: Help With T-sql Dateadd SP
25 Aug, 2008 - 09:05 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,208



Thanked: 213 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 online!Profile CardPM
+Quote Post

RudyVB.net
RE: Help With T-sql Dateadd SP
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
+Quote Post

RudyVB.net
RE: Help With T-sql Dateadd SP
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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:39PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month