Jason Eddie
Jason Eddie

Reputation: 13

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?

Upvotes: 1

Views: 1790

Answers (2)

Mike S
Mike S

Reputation: 306

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)

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269703

You can use convert() and no from clause:

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

or use 112:

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

Upvotes: 2

Related Questions