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 2005 Forums
 Transact-SQL (2005)
 TO_DATE conversion

Author  Topic 

fry
Starting Member

1 Post

Posted - 2008-05-02 : 10:20:49
Hello,

I am very new to SQL and was handed some Oracle code to put into a SQL Server 2005 db. A few errors come up, but the one I'm having the hardest time converting is:

INSERT INTO Reservations VALUES (102, TO_DATE('10/14/03', 'MM/DD/YY'),
22, TO_DATE('10/10/03', 'MM/DD/YY'));

and the error message that accompanies it upon parsing is:

Msg 195, Level 15, State 10, Line 86
'TO_DATE' is not a recognized built-in function name.

Any help converting this to SQL Server's liking would be greatly appreciated.

Thanks!

Fry

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-02 : 10:27:08
Make use of CAST or CONVERT function.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-02 : 10:31:07
1 Always use proper DATETIME datatype to store dates
2 Let front end application do the formation

Madhivanan

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

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-05-03 : 06:47:11
Oracle : INSERT INTO Reservations VALUES (102, TO_DATE('10/14/03', 'MM/DD/YY'),
22, TO_DATE('10/10/03', 'MM/DD/YY'));

SQL Server 2005:
INSERT INTO Reservations VALUES (102, CONVERT(varchar,'10/14/03',105),
22, CONVERT(varchar,'10/10/03',105));

The conversion varies from 101 to 108, i dont know exactly..
Place the conver styles from 101 to 109. and choose according to it..

Ganesh
Go to Top of Page
   

- Advertisement -