What is the equivalent of the Oracle “Dual” table in MS SqlServer?

前端 未结 4 2009
别那么骄傲
别那么骄傲 2021-01-01 08:10

What is the equivalent of the Oracle \"Dual\" table in MS SqlServer?

This is my Select:

SELECT pCliente,
       \'xxx.x.xxx.xx\' AS Serv         


        
4条回答
  •  借酒劲吻你
    2021-01-01 09:01

    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:

    Create a 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.

    Use a common table expression or a derived table

    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)
    

提交回复
热议问题