compute column


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: compute column

  1. #1
    Vick Guest

    compute column


    Hi,
    I've a problem to associate my function to a column, ie :
    ==================================================
    My function :
    CREATE FUNCTION computepercent(@thescore varchar(6))
    RETURNS numeric(10,2)
    AS
    BEGIN
    DECLARE @pastille numeric(10,2),
    @lanote_gch numeric(10,2),
    @lanote_max_dte numeric(10,2)

    SELECT @lanote_gch = CAST(LEFT(@lanote, CHARINDEX('/', @lanote) - 1)
    AS numeric(10,2))
    SELECT @lanote_max_dte = CAST(substring(@lanote, CHARINDEX('/', @lanote)
    + 1, LEN(@lanote)) AS numeric(10,2))

    IF @lanote_max_dte = 0.00
    BEGIN
    SELECT @pastille=0
    END
    ELSE
    BEGIN
    SELECT @pastille=(@lanote_gch/@lanote_max_dte)*100
    END


    RETURN @pastille
    END
    GO
    ==================================================
    (Example : thescore can be : '4/12' or '5/20' ....)
    create mytable ( thescore varchar(6), thepercent numeric(10,2) AS computepercent(thescore)
    )

    And I get the Error With SQL Server 2000 :
    Error validating the formula for column 'thepercent'


    Thanks.





  2. #2
    Rune Bivrin Guest

    Re: compute column

    "Vick" <v_rama@club-internet.fr> wrote in news:3d995b87$1@10.1.10.29:

    > ==================================================
    > (Example : thescore can be : '4/12' or '5/20' ....)
    > create mytable ( thescore varchar(6), thepercent numeric(10,2) AS
    > computepercent(thescore) )
    >
    > And I get the Error With SQL Server 2000 :
    > Error validating the formula for column 'thepercent'
    >
    >
    > Thanks.
    >
    >
    >
    >
    >


    try

    CREATE TABLE [dbo].[mytable] (
    [thescore] [varchar] (6),
    [thepercent] AS ([dbo].[computepercent]([thescore]))
    ) ON [PRIMARY]
    GO

    Enterprise manager doesn't like it, but it's correct.

    --
    Rune Bivrin
    - OOP since 1989
    - SQL Server since 1990
    - VB since 1991


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center