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
 General SQL Server Forums
 New to SQL Server Programming
 Update Columns in a Table

Author  Topic 

rao_aravin
Starting Member

1 Post

Posted - 2012-07-26 : 10:44:20
Hi ,

I am very new to SQL Server, jusdt started learning.

I have created a table named Employee and inserted the following values.However the datetime format I have given seems to be incorrect , so they appear as
Birthdate Date of Joining
1900-01-01 00:00:00.000 1900-01-01 00:00:00.000
Here is the query I have used :
insert into Employee values
(
'Rao','Aravinda','Mr.','',31/08/1985,23/05/2011,'A.P','Hyderabad','DSNR',500060,'India'
)

Now I need to correct the datetime format and update the values in the table.
I have tried a lot but did not get any thought .Please advise.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-07-26 : 10:55:41
Date/datetime values are not stored with a "format", so you can't "correct" it. You can change the way dates are displayed and interpreted using SET DATEFORMAT:

SET DATEFORMAT dmy;
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-07-26 : 11:21:10
You have to encapsulate your dates like a string: with single quotes. Also, when working with date literals, it's generally a good idea to use an unambiguous format like ANSI or ISO.

http://msdn.microsoft.com/en-us/library/ms187928.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-26 : 11:33:13
quote:
Originally posted by rao_aravin

Hi ,

I am very new to SQL Server, jusdt started learning.

I have created a table named Employee and inserted the following values.However the datetime format I have given seems to be incorrect , so they appear as
Birthdate Date of Joining
1900-01-01 00:00:00.000 1900-01-01 00:00:00.000
Here is the query I have used :
insert into Employee values
(
'Rao','Aravinda','Mr.','',31/08/1985,23/05/2011,'A.P','Hyderabad','DSNR',500060,'India'
)

Now I need to correct the datetime format and update the values in the table.
I have tried a lot but did not get any thought .Please advise.



datetime values are internal represented as integer and by default displays itself in iso format yyyymmdd

see

http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -