?
Solved

How to convert years into months

Posted on 2008-10-01
8
Medium Priority
?
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 143

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 960 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 1040 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:fahVB
ID: 22618872
if period = days, and term = 1------this never happens
0
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

743 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