dbTalk Databases Forums  

insert current date/time

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss insert current date/time in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ryan.mclean@gmail.com
 
Posts: n/a

Default insert current date/time - 05-12-2005 , 06:40 PM






Hi all, I have a question about inserting records into sql server. I
am brand new to sql server, always using oracle previously. Before
today, I had always written statement such as this:

INSERT INTO TABLE (COL1) VALUES SYSDATE;

How is this accomplished in sql? I am using a datetime data type, I
hope that is correct . . .

Thank you for your help.
Ryan

p.s. I tried getdate(), getdate, sysdate, and current_timestamp. All
to no avail


Reply With Quote
  #2  
Old   
The Gekkster via SQLMonster.com
 
Posts: n/a

Default Re: insert current date/time - 05-12-2005 , 11:10 PM






Hi Ryan,

I'm new to SQL Server myself, but for your question, this works for me:

INSERT INTO MyTable (colA)
VALUES (GetDate())

HTH

--
Message posted via http://www.sqlmonster.com

Reply With Quote
  #3  
Old   
Chandra
 
Posts: n/a

Default Re: insert current date/time - 05-12-2005 , 11:22 PM



INSERT INTO TABLE (COL1) VALUES SELECT getdate()

--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.developersdex.com/gurus/default.asp?p=4223
---------------------------------------


Reply With Quote
  #4  
Old   
Chandra
 
Posts: n/a

Default Re: insert current date/time - 05-12-2005 , 11:28 PM



correction

INSERT INTO TABLE (COL1) SELECT getdate()
or
SELECT getdate() INTO TABLE


best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.developersdex.com/g*urus/default.asp?p=4223


Reply With Quote
  #5  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: insert current date/time - 05-13-2005 , 06:11 PM



On 12 May 2005 16:40:38 -0700, ryan.mclean (AT) gmail (DOT) com wrote:

Quote:
Hi all, I have a question about inserting records into sql server. I
am brand new to sql server, always using oracle previously. Before
today, I had always written statement such as this:

INSERT INTO TABLE (COL1) VALUES SYSDATE;
Hi Ryan,

Is this a straight copy-and-paste from working Oracle code? The SQL
standard calls for parentheses in the values clause.


(snip)
Quote:
p.s. I tried getdate(), getdate, sysdate, and current_timestamp. All
to no avail
Both CURRENT_TIMESTAMP (the ANSI-standard keyword) and getdate() (the
T-SQL proprietary equivalent) should work - but only if you include the
parentheses, and escape the tablename ("table" is a reserved word):

INSERT INTO "TABLE" (COL1) VALUES (CURRENT_TIMESTAMP);

If this doesn't work, then post back with the DDL (the CREATE TABLE
statement used for your table "TABLE"), the complete code, and the exact
error message you get.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Reply With Quote
  #6  
Old   
ryan.mclean@gmail.com
 
Posts: n/a

Default Re: insert current date/time - 05-15-2005 , 05:02 PM



Hi everyone! Thanks for all of your responses . . . I believe my
problem was I was trying to insert getdate() into the datetime column
in question using the enterprise manager gui thingy. When I try the
same as an insert statement, it works fine. I was giving the
enterprise manager too much credit

Thanks again and have a great weekend!
Ryan


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.