January 22, 2008 at 2:51 am
hi all,
Is there anything like dual in sql server ?
regards
Josh
January 22, 2008 at 2:56 am
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
January 23, 2008 at 6:53 am
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.
January 23, 2008 at 10:58 am
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
January 25, 2008 at 5:55 am
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.
January 25, 2008 at 10:07 am
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
January 25, 2008 at 10:09 am
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