Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Add current date

Author  Topic 

ann
Posting Yak Master

220 Posts

Posted - 2006-10-19 : 10:36:33
How can I add the current date into this sp (I want to add the current date into the Processed Table during the insert):

insert into Processed(AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments)
select AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments
from tempComp

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-19 : 10:38:29
To obtain current date

use getdate() for current date & time

if you only want the date

use dateadd(day, datediff(day, 0, getdate()), 0)


KH

Go to Top of Page

ann
Posting Yak Master

220 Posts

Posted - 2006-10-19 : 10:53:49
So I would do something like this?:
insert into Processed(AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments, GetDate())
select AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments
from tempComp
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-19 : 11:11:28
No, you need a date processed column in the table you're inserting into, create a new column using the datetime or smalldatetime data type, then insert like this
insert into Processed(AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments, DateProcessed)
select AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments, getdate()
from tempComp

Go to Top of Page

ann
Posting Yak Master

220 Posts

Posted - 2006-10-19 : 11:11:36
ok, so that doesn't work, so I tried this, but it doesn't work either:

Declare @now datetime
set @now = GetDate()

insert into Processed(AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments, @now)
select AcctNum, AcctPrevious, CardNum, CaseNumber,
AvailBalance,Comments
from tempComp

but I get: Incorrect syntax near '@now'
does anyone know what\how I should do this?
Go to Top of Page

ann
Posting Yak Master

220 Posts

Posted - 2006-10-19 : 11:13:53
snSQL - I posted my reply before seeing yours - I did yours and it works perfect.
Thank you for taking the time to help, I really appreciate it
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-21 : 07:39:36
or you can define that column to have GetDate() as default value

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -