Monday, March 19, 2012

Oracle To SQLServer conversion for SELECT TO_CHAR(SYSDATE,DDMMYYYYHHMMSS)

Hi,

i am trying to convert the following oracle sql,

SELECT TO_CHAR(SYSDATE,'DDMMYYYYHHMMSS')
(oraclequery)
into a MSSQLServer sql query.

Could you help me to get the equivalent of the above query in sqlserver.

PS: i tried using the following query, but i cannot get the month equivalent as 01/02/03/04 instead i get january/febrauary/march, etc

SELECT
(DATENAME(d, GETDATE())+
DATENAME(m, GETDATE())+
DATENAME(yyyy, GETDATE())+
DATENAME(hh, GETDATE())+
DATENAME(mi, GETDATE())+
DATENAME(ss, GETDATE()))
AS "Month Name"
(ms sqlserver)
The above query gives output as "6November2004174837"

what i need as result is "06112004174837"

Thanks,
Gopi.
Follow your DREAMS...select replace(convert(char(10),getdate(),104),'.','')
+replace(convert(char(8),getdate(),14),':','')|||Thank you SQL Consultant. The following query also works.

SELECT
CASE
WHEN LEN(DATENAME(d, GETDATE())) = 1
THEN '0'+DATENAME(d, GETDATE())
ELSE
DATENAME(d, GETDATE()) END+
CAST(MONTH(GETDATE()) AS VARCHAR)+
DATENAME(yyyy, GETDATE())+
DATENAME(hh, GETDATE())+
DATENAME(mi, GETDATE())+
DATENAME(ss, GETDATE())
AS "Month Name"

Thanks,
Gopi.
Follow your DREAMS...|||actually, Registered User, that will not work in january through september

No comments:

Post a Comment