468,309 Members | 1,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,309 developers. It's quick & easy.

insert current date/time

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 :(

Jul 23 '05 #1
5 164478
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
Jul 23 '05 #2
INSERT INTO TABLE (COL1) VALUES SELECT getdate()

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

Jul 23 '05 #3
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

Jul 23 '05 #4
On 12 May 2005 16:40:38 -0700, ry*********@gmail.com wrote:
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)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)
Jul 23 '05 #5
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

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by vishal | last post: by
2 posts views Thread by toedipper | last post: by
2 posts views Thread by mattmerc | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.