简体   繁体   中英

Migrating from Oracle to SQL server. Dual table select query -> SQL server

I am moving from Oracle into a sql server 2008.

I had some query for the dual table in my system,

SELECT TO_CHAR(TRUNC(sysdate, 'DAY')-0,'YYYYMMDD') FROM DUAL

Since there is no Dual table in SQL server, how can i achieve the same result with getdate with convert on the SQL Server ?

I have also heard adding a dummy table for dual, but should that work for my query?

You can use convert() and no from clause:

SELECT REPLACE(CONVERT(VARCHAR(10), getdate(), 121), '-', '')

or use 112:

SELECT CONVERT(VARCHAR(8), getdate(), 112)

In SQL Server FROM TABLE is optional but it could be still required in case of JOIN and other complex syntax with aliases, best way to create it.

Select 'x' C into dbo.Dual
(1 row affected)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM