dual in sql server

  • hi all,

    Is there anything like dual in sql server ?

    regards

    Josh

  • No dual is not there in SQL Server

    Check for the following link for more clarifications.

    http://vyaskn.tripod.com/oracle_sql_server_differences_equivalents.htm

  • No, SQL Server doesn't conform to the generally accepted/ANSI standard that you must SELECT from "something" (table or view).

    So you can just SELECT a constant. E.g., SELECT 'foo'; vs. SELECT 'foo' FROM dual;

    That said, should you wish to write portable (SQL Server / Oracle) code, there is nothing that says you cannot create your own DUAL table. In fact, I've done it. Just follow the same table DDL as Oracle's DUAL table.


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • I have in fact created a DUAL table in some of my databases in the past for various uses, esp. if I have to translate Oracle SQL.

    Here's what it looks like:

    CREATE TABLE [dbo].[dual](

    [dummy] [char](1) NOT NULL

    ) ON [PRIMARY]

    SELECT *

    FROM dual

    dummy

    -----

    X

    (1 row(s) affected)

    G. Milner

  • JohnG (1/23/2008)


    No, SQL Server doesn't conform to the generally accepted/ANSI standard that you must SELECT from "something" (table or view).

    So you can just SELECT a constant. E.g., SELECT 'foo'; vs. SELECT 'foo' FROM dual;

    That said, should you wish to write portable (SQL Server / Oracle) code, there is nothing that says you cannot create your own DUAL table. In fact, I've done it. Just follow the same table DDL as Oracle's DUAL table.

    Please pardon my ignorance in asking this question. I've never used Oracle and it's been years since I used any SQL-based database other than SQL Server, so I don't remember how they operated.

    In SQL Server you can have the following:

    Declare @MyDate datetime;

    Select @MyDate = Getdate();

    Based on what I've read in this thread, does the value in Getdate() have to reside in a table in order to be Selected into the variable? This is, of course, one example. It could just as easily be adding 1 to the value stored in a variable.

    I ask because I inherited a database whose code was originally designed to run in either SQL Server or Oracle (we have since standardized on SQL Server) and I have wondered about some of the apparent gyrations the code goes through to accomplish apparently simple tasks. What I thought were gyrations may simply have been differences in the way the two databases work.

  • Hi. You can think of GETDATE() as a system function that returns a (scalar) value that you assign to your variable. In this case, either SET or SELECT will work for assignment:

    DECLARE @MY_DATE AS DATETIME

    SET @MY_DATE = GETDATE()

    PRINT @MY_DATE

    DECLARE @MY_DATE AS DATETIME

    SELECT @MY_DATE = GETDATE()

    PRINT @MY_DATE

    G. Milner

  • gdmilner (1/25/2008)


    Hi. You can think of GETDATE() as a system function that returns a (scalar) value that you assign to your variable. In this case, either SET or SELECT will work for assignment:

    DECLARE @MY_DATE AS DATETIME

    SET @MY_DATE = GETDATE()

    PRINT @MY_DATE

    DECLARE @MY_DATE AS DATETIME

    SELECT @MY_DATE = GETDATE()

    PRINT @MY_DATE

    Is that in Oracle? I was trying to get at the function of the Dual table.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply