Here is another post addition to the Oracle to Microsoft SQL Server series, This time we discuss about the DUAL table feature that is available in Oracle. However SQL server doesn't support queries on DUAL table as it is not present in the database.
SELECT 1 FROM DUAL returns invalid object name error in MSSQL Server. -
Msg 207, Level 16, State 1, Line 1
Invalid column name 'SYSDATETIME'.
Dual object invalid in MS SQL Server. |
Dual table is a one row table that Oracle provides where you can do one row calculations, use to display SYSDATE, test functions with default values etc. eg:-
SELECT SYSDATE FROM DUAL - returns the system date from the database server.
SELECT (9*50) FROM DUAL; - returns 450
Solution or Alternative to DUAL in MS SQL server is as below,
In MSSQL, Any function, calculation, string after SELECT works, Please find the below examples along with screenshot.
SELECT GETDATE() - returns the system date.
SELECT (9*50) - returns 450
SELECT 'Hello World'
Dual alternative in SQL Server. |
An alternative to this syntax is to create a DUAL table in MS SQL server with the Dummy column and value 'X' under it. However you have to make sure you that all the users have access this to table to be used just as in Oracle database.
No comments:
Post a Comment