Professional Web Applications Themes

Where/when to fill an empty field ? - Microsoft SQL / MS SQL Server

I have a table in which one of the fields has a value calculated based on an stored procedure. This value has to be left blank by the application and filled by the database in any way. The way I found to do this is to create a trigger for insert, in which this value is filled by issuing an update. My first original idea was to alter the value of the "inserted" table but I found that's not possible. I don't like the current approach, because it really generate a 2nd operation, I mean, it is an update just ...

  1. #1

    Default Where/when to fill an empty field ?


    I have a table in which one of the fields has a value calculated based on an
    stored procedure.

    This value has to be left blank by the application and filled by the
    database in any way.

    The way I found to do this is to create a trigger for insert, in which this
    value is filled by issuing an update. My first original idea was to alter
    the value of the "inserted" table but I found that's not possible.

    I don't like the current approach, because it really generate a 2nd
    operation, I mean, it is an update just a little after the insert is
    performed.

    Is there any other way to do this without causing this two steps operation ?


    Thanks in advance,





    Tim Guest

  2. #2

    Default Re: Where/when to fill an empty field ?

    depending on what the calculated value is, why not just create a
    computed/calculated column.

    e.g.
    create table t(i int, j as i*2-1)
    insert t values(123)
    select * from t

    --
    -oj
    RAC v2.2 & QALite!
    http://www.rac4sql.net


    "Tim Conner" <com> wrote in message
    news:phx.gbl... 
    an 
    this 



    oj Guest

  3. #3

    Default Re: Where/when to fill an empty field ?


    The calculated field is not the result of basic math operations.
    It has to make some searches on other tables and give different values
    depending on values found.
    That's why this calculated field is calculated on a stored procedure.

    Regards,



    "oj" <com> wrote in message
    news:eMK%phx.gbl... 
     [/ref]
    on 
    > this [/ref]
    alter [/ref]
    operation 
    >
    >[/ref]


    Tim Guest

  4. #4

    Default Re: Where/when to fill an empty field ?

    It may not be the answer you want, but, if you are using SQL 2000.
    You could create a user defined function and include that function in the
    definition of the calculated column.
    You would have no need of the trigger and the stored procedure in that case.

    "Tim Conner" <com> wrote in message
    news:phx.gbl... 
    > [/ref]
    > on 
    > > this [/ref]
    > alter [/ref]
    > operation 
    > >
    > >[/ref]
    >
    >[/ref]


    raydan Guest

  5. #5

    Default Re: Where/when to fill an empty field ?

    raydan is correct. you could put the logic into an udf and use it for your
    calc column.

    --
    -oj
    RAC v2.2 & QALite!
    http://www.rac4sql.net


    "Tim Conner" <com> wrote in message
    news:phx.gbl... 
    > [/ref]
    > on 
    > > this [/ref]
    > alter [/ref]
    > operation 
    > >
    > >[/ref]
    >
    >[/ref]


    oj Guest

  6. #6

    Default Re: Where/when to fill an empty field ?

    Why thank you sir. :-)

    "oj" <com> wrote in message
    news:%phx.gbl... 


    raydan Guest

Similar Threads

  1. Forms: Text field - auto fill another field?
    By LDVDG@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 3
    Last Post: May 18th, 05:35 PM
  2. Replies: 12
    Last Post: October 14th, 01:53 AM
  3. Fill a field from the previous record
    By Bruce Rodtnick in forum Microsoft Access
    Replies: 3
    Last Post: August 1st, 11:11 PM
  4. fill fields by value of another field
    By Bish in forum Microsoft Access
    Replies: 1
    Last Post: July 31st, 07:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139