caluculate the rangeof date values and roundoff the output value

Posted by Santosh198318 under Sql Server on 6/21/2016 | Points: 10 | Views : 596 | Status : [Member] | Replies : 2
need a help on get the roundoff value..
where i am passing parameters is coming like month or day or week or year..
i need to convert those values onto days and caluculate the range then i have to roundoff the values as per the requirement
right now i have inserted the list of days , weeks , months and years in the database table.(but this is not the correct way to do this , for an emergecy i have inserted those values getting the roundoff values..)
created funtion:
CREATE FUNCTION [dbo].[fn_conv_Get_DurationAndUnit]  
(
@Duration INT
,@DurationUnit VARCHAR(100)
)

RETURNS VARCHAR(250)
AS BEGIN
DECLARE @ReturnDurationUnit VARCHAR(250)
SET @ReturnDurationUnit = (CONVERT(VARCHAR(10),@Duration) + ' ' + LTRIM(RTRIM(@DurationUnit)))
RETURN @ReturnDurationUnit
END

in db insert values like
input value destination value
1 Weeks 1
10 Days 2
11 Days 2
12 Days 2
13 Days 2
14 Days 2
2 Weeks 2
" " "
"
15 Days 3
16 Days 3
17 Days 3
18 Days 3
19 Days 3
3 Weeks 3
20 Days 4
1 Month 4
60 Days 12
480 Days 96
96 Weeks 96
24 Months 96


i need this as more dynamic...please let me know if you have any Questions.




Responses

Posted by: Bandi on: 6/22/2016 [Member] [MVP] Platinum | Points: 25

Up
0
Down
what is your actual requirement ? Is it something like you need to calculate how many days, how many weeks and so on for the given two date inputs?

if not, let us know your requirement clearly so that we can help you

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh198318 on: 6/23/2016 [Member] Starter | Points: 25

Up
0
Down
Hi Bandi,
yes, i need to calculate how many days, how many weeks and months ... so on(here input value is coming like 1 day or 1 week or 1 month ...input parameters duration is int and duration unit is like day or week or month or year ), and need to calculate in which date range it will come we have to check and need to return the destination value .please find the attachment ,
please let me know if you have any questions
 Download source file

Santosh198318, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response