Solved

How to convert years into months

Posted on 2008-10-01
8
735 Views
Last Modified: 2012-06-21
In my database i have two fields, period and term, sometimes period is right, but sometimes not

if period has months, then leave it
but if period has something ele in it then that needs to be converted into months etc years,days,weeks

for example
Period             Term
years               3

so, in this case term needs to be 36

any ideas....

0
Comment
Question by:fahVB
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22618711
if period = days, and term = 1 for example, what do you want to be the output?

meanwhile, check out the CASE statement...
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 240 total points
ID: 22618742
some sort of case statement should suffice:

select case period when years then term * 12
when days then term /31
end
from table

There are more calculations to work in there, but this shoudl get you started on one way to do this.  Maybe put the case in a function to use later.
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 260 total points
ID: 22618766
no points please.

Just make sure you put 'years' or 'months' in quotes since it's a string.

select case period when 'years' then term * 12
when 'Months' then term
end
from table

0
 

Author Comment

by:fahVB
ID: 22618872
if period = days, and term = 1------this never happens
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:fahVB
ID: 22618887
angelIII, there is no case stmt
0
 

Author Comment

by:fahVB
ID: 22618918
How about weeks and semimonths
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22618973
Trying to translate everything into a larger unit of measure is tough.  How many months is 7 weeks?  2?  What if it spans from end of april to the beginning of june?  Is that still 2?
0
 

Author Closing Comment

by:fahVB
ID: 31502156
Thank you
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now