Professional Web Applications Themes

column calculations - Microsoft SQL / MS SQL Server

create a computed column to add year to the existing column See following example. CREATE TABLE dbo.t2 ( dt datetime NULL, next_yr AS dateadd(year,1,dt), modified datetime NULL default getdate() ) --to keep track of when the record is updated use trigger. create trigger tr_t2 on t2 for update as update a set modified = getdate() from t2 a, inserted b where a.dt=b.dt -- -Vishal "Leon Shaw" <vnalitymsn.com> wrote in message news:ORjRjJnRDHA.2232TK2MSFTNGP11.phx.gbl... > How do I program a cell within a table row insert the current date into a > particular cell, then have another cell within that same row insert ...

  1. #1

    Default Re: column calculations

    create a computed column to add year to the existing column
    See following example.

    CREATE TABLE dbo.t2
    (
    dt datetime NULL,
    next_yr AS dateadd(year,1,dt),
    modified datetime NULL default getdate()
    )

    --to keep track of when the record is updated use trigger.

    create trigger tr_t2 on t2
    for update as
    update a set modified = getdate()
    from t2 a, inserted b
    where a.dt=b.dt

    --
    -Vishal

    "Leon Shaw" <vnalitymsn.com> wrote in message
    news:ORjRjJnRDHA.2232TK2MSFTNGP11.phx.gbl...
    > How do I program a cell within a table row insert the current date into a
    > particular cell, then have another cell within that same row insert a date
    > which is one year in the future from the current date cell, and one more
    > field that keep the dates of all updates to that particular row.
    >
    > Example:
    > CurrentDate FutureDate LastUpdate
    > 07/09/03 07/09/04 08/15/03
    >
    >

    Vishal Parkar Guest

  2. #2

    Default Re: column calculations

    It maybe better just to do this calculation inside of my webpage code and
    send the calculated information back to the database. Right?
    "Vishal Parkar" <vgparkarhotmail.com> wrote in message
    news:e3ECeQnRDHA.2188TK2MSFTNGP10.phx.gbl...
    > create a computed column to add year to the existing column
    > See following example.
    >
    > CREATE TABLE dbo.t2
    > (
    > dt datetime NULL,
    > next_yr AS dateadd(year,1,dt),
    > modified datetime NULL default getdate()
    > )
    >
    > --to keep track of when the record is updated use trigger.
    >
    > create trigger tr_t2 on t2
    > for update as
    > update a set modified = getdate()
    > from t2 a, inserted b
    > where a.dt=b.dt
    >
    > --
    > -Vishal
    >
    > "Leon Shaw" <vnalitymsn.com> wrote in message
    > news:ORjRjJnRDHA.2232TK2MSFTNGP11.phx.gbl...
    > > How do I program a cell within a table row insert the current date into
    a
    > > particular cell, then have another cell within that same row insert a
    date
    > > which is one year in the future from the current date cell, and one more
    > > field that keep the dates of all updates to that particular row.
    > >
    > > Example:
    > > CurrentDate FutureDate LastUpdate
    > > 07/09/03 07/09/04 08/15/03
    > >
    > >
    >
    >

    Leon Shaw Guest

  3. #3

    Default Re: column calculations

    Thanks so much Vishal!

    "Vishal Parkar" <vgparkarhotmail.com> wrote in message
    news:uNLNYdnRDHA.1688TK2MSFTNGP11.phx.gbl...
    > yes, instead of writing trigger it would always be better to update the
    date
    > column for "modified record" inside your webpage rather than putting in
    > trigger. Also while inserting instead of using "formlae column" you can
    > implement the same logic in INSERT statment.
    > if you put the similar logic into your application code, it will
    definitely
    > be a clean coding. I have shown you the option how can you implement this
    at
    > database level.
    >
    > --
    > -Vishal
    >
    > "Leon Shaw" <vnalitymsn.com> wrote in message
    > news:eGBLzYnRDHA.1220TK2MSFTNGP12.phx.gbl...
    > > It maybe better just to do this calculation inside of my webpage code
    and
    > > send the calculated information back to the database. Right?
    > > "Vishal Parkar" <vgparkarhotmail.com> wrote in message
    > > news:e3ECeQnRDHA.2188TK2MSFTNGP10.phx.gbl...
    > > > create a computed column to add year to the existing column
    > > > See following example.
    > > >
    > > > CREATE TABLE dbo.t2
    > > > (
    > > > dt datetime NULL,
    > > > next_yr AS dateadd(year,1,dt),
    > > > modified datetime NULL default getdate()
    > > > )
    > > >
    > > > --to keep track of when the record is updated use trigger.
    > > >
    > > > create trigger tr_t2 on t2
    > > > for update as
    > > > update a set modified = getdate()
    > > > from t2 a, inserted b
    > > > where a.dt=b.dt
    > > >
    > > > --
    > > > -Vishal
    > > >
    > > > "Leon Shaw" <vnalitymsn.com> wrote in message
    > > > news:ORjRjJnRDHA.2232TK2MSFTNGP11.phx.gbl...
    > > > > How do I program a cell within a table row insert the current date
    > into
    > > a
    > > > > particular cell, then have another cell within that same row insert
    a
    > > date
    > > > > which is one year in the future from the current date cell, and one
    > more
    > > > > field that keep the dates of all updates to that particular row.
    > > > >
    > > > > Example:
    > > > > CurrentDate FutureDate LastUpdate
    > > > > 07/09/03 07/09/04 08/15/03
    > > > >
    > > > >
    > > >
    > > >
    > >
    > >
    >
    >

    Leon Shaw Guest

Similar Threads

  1. Calculations not working
    By Elliott_Steinberg@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 10
    Last Post: October 6th, 09:40 PM
  2. Calculations in a form
    By Kathy_Neal@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 2
    Last Post: December 8th, 02:10 PM
  3. calculations in Acrobat 5
    By lreiner@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 1
    Last Post: April 9th, 06:49 PM
  4. Calculations with date
    By Danield in forum PERL Beginners
    Replies: 3
    Last Post: January 19th, 12:00 AM
  5. date calculations
    By Fredg in forum Microsoft Access
    Replies: 4
    Last Post: July 25th, 02:53 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