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.
| Author |
Topic |
|
rbpd5015
Starting Member
4 Posts |
Posted - 2012-06-07 : 10:00:42
|
| Ok I am moving from Excel to SQL LOL..... I could really use some help.I just imported my entire Business Employee Database into SQL from Excel.I have two fields that are calculated and that is AGE and Class years.These are calculated based on DOB and Date Date of Class.Now since I am moving to SQL those numbers will be static and never change so what must I do to make them calculate again? How does SQL handle this?Thanks,Matt |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-07 : 10:05:21
|
| Have they been imported as populated columns?You would have to drop them then add a calculated columnmycol as mycol1 - mycol2Also check your dates and datatypes as sometimes they cause problems.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
rbpd5015
Starting Member
4 Posts |
Posted - 2012-06-07 : 14:12:44
|
| Ok I am in the 2008 studio managerI have a column calledemp_DOBand below it emp_AgeI am in the age column now and clickedCOMPUTED COLUMN SPECIFICATIONbelow it is formula.What formula can I put in to calculate the age of the Employee?Matt |
 |
|
|
rbpd5015
Starting Member
4 Posts |
Posted - 2012-06-07 : 14:25:59
|
| I was told to use thisfloor(datediff(day, [DateOfBirth], getdate())/(365.25))but it doesnt seem to work correct |
 |
|
|
Ida Hoe
Starting Member
3 Posts |
Posted - 2012-06-07 : 14:32:03
|
quote: Originally posted by rbpd5015 Ok I am moving from Excel to SQL LOL..... I could really use some help.I just imported my entire Business Employee Database into SQL from Excel.I have two fields that are calculated and that is AGE and Class years.These are calculated based on DOB and Date Date of Class.Now since I am moving to SQL those numbers will be static and never change so what must I do to make them calculate again? How does SQL handle this?Thanks,Matt
If I were running reports using sql query, I would not bother to store the age, I would recalculate every time I chose the data. SELECT DOB,GETDATE()as today,DATEDIFF(yy,moddate,GETDATE())-CASEwhen DATEADD(yy,datediff(yy,moddate,getdate()),moddate) > GETDATE() then 1else 0end as AGE FROM MyNewTable; Or use this same logic to UPDATE AGE periodically, or create a procedure .... |
 |
|
|
rbpd5015
Starting Member
4 Posts |
Posted - 2012-06-07 : 14:41:11
|
| I have it setup to display as a gridview on a webpage. So I better off just having the age calculated each time the PAGE is loaded instead of worrying about creating a calculated field? |
 |
|
|
Ida Hoe
Starting Member
3 Posts |
Posted - 2012-06-07 : 14:47:00
|
| Well, that is the way I would do it - then it's always up to the minute just like a computed column - Either way works. The calculation is the same. |
 |
|
|
|
|
|
|
|