Showing posts with label to_char. Show all posts
Showing posts with label to_char. Show all posts

Monday, March 19, 2012

Oracle's TO_CHAR, what in SQL Server 2005?

Greetings,

In oracle i use the following sentence TO_CHAR(Table1.DateIn, ,'mm/yyyy') within a query. I need how to replace this for using it in SQL Server. I tried to use the SQL Server CONVERT function but nothing work. Could you help me?

Thank you in advance,

Fernando

use convert(varchar,table1.dateIn)|||SUBSTRING(CONVERT(varchar(10), Table1.Dateln, 103), 4, 7)

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