Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 simple query

Author  Topic 

mattsterrett11
Starting Member

6 Posts

Posted - 2012-03-13 : 12:33:05
Hi guys, I have a simple query for whoever can help, i should know this but I have been racking my brain most of today for how to do it.

I have two colums in a table (mothersAge and Fathers Age), i also have a third called AgeDifference..can anyone help me how to figure out the difference from fathers age to mothers age?

ie if father was 40 and mother was 38 the third column would read 2, or if father was 38 and mother was 40 the column would read -2?

Many thanks to whoever helps, just having one of those days...

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-03-13 : 13:05:47
Really? Ok.

UPDATE yourTable SET ageDifference = FathersAge - MothersAge;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-13 : 14:58:35
i hope both columns are of NOT NULL type else you've see how you handle NULL values in them

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

mattsterrett11
Starting Member

6 Posts

Posted - 2012-03-14 : 06:28:26
cheers guys, managed to get it sorted but thanks for a quick reply.

Just had an off day...lack of coffee i think =]
Go to Top of Page
   

- Advertisement -