Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

insert current date/time

0 views
Skip to first unread message

ryan....@gmail.com

unread,
May 12, 2005, 7:40:38 PM5/12/05
to
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 :(

The Gekkster via SQLMonster.com

unread,
May 13, 2005, 12:10:54 AM5/13/05
to
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

Chandra

unread,
May 13, 2005, 12:22:28 AM5/13/05
to
INSERT INTO TABLE (COL1) VALUES SELECT getdate()

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

Chandra

unread,
May 13, 2005, 12:28:17 AM5/13/05
to
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

Hugo Kornelis

unread,
May 13, 2005, 7:11:09 PM5/13/05
to
On 12 May 2005 16:40:38 -0700, ryan....@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)

ryan....@gmail.com

unread,
May 15, 2005, 6:02:24 PM5/15/05
to
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

0 new messages