Thread: Column logic

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    144
    Rep Power
    8

    Column logic


    Hi, is there a way to make simple logic for columns in a table? For example, if a value in 2 columns are equal, then set a third column to TRUE.

    Thanks
    Cheers,
    Fred Liu
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,179
    Rep Power
    4279
    yes, but you would want to do this only in a SELECT query, not in the table itself as an actual column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    144
    Rep Power
    8
    Originally Posted by r937
    yes, but you would want to do this only in a SELECT query, not in the table itself as an actual column
    Why is it not a good idea for the actual table to automatically change the 3rd column once the previous 2 columns are equal? I don't want to have to run a SELECT statement each time the table is updated.
    Cheers,
    Fred Liu
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    724
    Rep Power
    291
    Seems like it would be another field to keep track of. Just worry about it at "run time".

    That is the point r937 is trying to get across.
  8. #5
  9. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,179
    Rep Power
    4279
    Originally Posted by fred2028
    I don't want to have to run a SELECT statement each time the table is updated.
    i agree completely, and you're in luck, you don't have to

    just do your updates as normal, and of course don't update this mythical third column because it won't even be there

    when you want to see the data, that's the only time you do the SELECT, and that includes the calculation


    Last edited by r937; May 29th, 2012 at 08:37 PM.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    144
    Rep Power
    8
    Originally Posted by r937
    i agree completely, and you're in luck, you don't have to

    just do your updates as normal, and of course don't update this mythical third column because it won't even be there

    when you want to see the data, that's the only time you do the SELECT, and that includes the calculation


    OK thanks!
    Cheers,
    Fred Liu

IMN logo majestic logo threadwatch logo seochat tools logo