What is the equivalent of the Oracle "Dual" table in MS SqlServer?
This is my Select:
SELECT pCliente,
'xxx.x.xxx.xx' AS Servidor,
xxxx AS Extension,
xxxx AS Grupo,
xxxx AS Puerto
FROM DUAL;
What is the equivalent of the Oracle "Dual" table in MS SqlServer?
This is my Select:
SELECT pCliente,
'xxx.x.xxx.xx' AS Servidor,
xxxx AS Extension,
xxxx AS Grupo,
xxxx AS Puerto
FROM DUAL;
On
While you usually don't need a DUAL table in SQL Server as explained by Jean-François Savard, I have needed to emulate DUAL for syntactic reasons in the past. Here are three options:
DUAL table or view-- A table
SELECT 'X' AS DUMMY INTO DUAL;
-- A view
CREATE VIEW DUAL AS SELECT 'X' AS DUMMY;
Once created, you can use it just as in Oracle.
If you just need DUAL for the scope of a single query, this might do as well:
-- Common table expression
WITH DUAL(DUMMY) AS (SELECT 'X')
SELECT * FROM DUAL
-- Derived table
SELECT *
FROM (
SELECT 'X'
) DUAL(DUMMY)
On
This could be of some help I guess, when you need to join some tables based on local variables and get the information from those tables:
Note: Local variables must have been
Select @XCode as 'XCode '
,@XID as 'XID '
,x.XName as 'XName '
,@YCode as 'YCode '
,@YID as 'YID '
,y.YName as 'YName '
From (Select 1 as tst) t
Inner join Xtab x on x.XID = @XID
Inner join Ytab y on y.YID = @YID
On
It's much simpler than that. Use literal values to establish data types. Put quotes around column names if they need special characters. Skip the WHERE clause if you need 1 row of data:
SELECT 'XCode' AS XCode
,1 AS XID
,'XName' AS "X Name"
,'YCode' AS YCode
,getDate() AS YID
,'YName' AS "Your Name"
WHERE 1 = 0
In
sql-server, there is nodualyou can simply doHowever, if your problem is because you transfered some code from
Oraclewhich reference todualyou can re-create the table :