Serge Rielau <sr*****@ca.ibm.com> wrote in message news:<2s*************@uni-berlin.de>...
Henning,
DB2 supports "expression generated" columns.
CREATE TABLE T (c1 INT, c2 INT GENERATED ALWAYS AS (c1 * 2));
The difference between this feature and the one from SQL Server is that
the values in DB2 are persistent in the table. They are not computed
upon reference, but on update/insert.
SQL Server 2005 calls this PERSISTED
(shame on MS for not following the standard, DB2 Dev worked hard to make
the two varieties compatible)
To achieve the exact same behaviour in DB2 as in SQL Server 2000 you
would use a view.
I am rather curious though: What to you use computed columns in SQL
server for? I never figured out what this SQL Server 2000 feature is
good for....
Cheers
Serge
Hei Serge,
Tank you for your answer.
My task is to use some rather complex SQL (used for reservation
system) and use the value from SQL as value in field.
For instance i want to do this (simple eksample):
Create a field called "Numbs"
Define a function CalculateNumbs()
This function would look like this in SQL-server:
CREATE FUNCTION dbo.CalculateNumbs (@TYPE AS char(1))
RETURNS decimal (13,0)
AS
BEGIN
DECLARE @ANTAL AS decimal(13,0)
SELECT count(*) as @ANTAL from tabel where itemtype = @TYPE
IF @@ERROR <> 0
SELECT @ANTAL = -2
RETURN @ANTAL
END
This Function CalculateNumbs is used on field Numbs.
The purpose of this is isolating complex SQL rather than doing it in
program.
It has a lot of other atvantaged too, so that why we use it.
But is it possible to do something like this in DB2 ?
/Henning