Reputation: 13
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
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
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