How to add selected days in particular date column

Posted by Karthik2010_Mca under Sql Server on 5/27/2014 | Points: 10 | Views : 435 | Status : [Member] | Replies : 2
Hi,

How to add selected days in particular date column.


Current Output:
Dt_BatchStartDate I_Admission_GraceDays

2014-05-05 00:00:00.000 NULL
2014-05-21 00:00:00.000 10
2014-06-06 00:00:00.000 NULL
2014-06-10 00:00:00.000 5
2014-05-05 00:00:00.000 NULL
2014-05-05 00:00:00.000 30

Expected Output:
Dt_BatchStartDate I_Admission_GraceDays

2014-05-05 00:00:00.000 NULL
2014-05-31 00:00:00.000 10
2014-06-06 00:00:00.000 NULL
2014-06-15 00:00:00.000 5
2014-05-05 00:00:00.000 NULL
2014-06-04 00:00:00.000 30

The below mentioned query getting current output.

SELECT
A.Dt_BatchStartDate ,A.I_Admission_GraceDays
FROM T_Student_Batch_Master A
INNER JOIN T_Center_Batch_Details B
ON B.I_Batch_ID=A.I_Batch_ID
AND B.I_Centre_Id = 767
AND B.I_Status = 4
AND A.AllowOnlineAddmission = 1
INNER JOIN T_Course_Master C
ON C.I_Course_ID= A.I_Course_ID
AND C.I_CourseFamily_ID = 535
AND C.I_Brand_ID = 1
--AND A.Dt_BatchStartDate > GETDATE()
INNER JOIN dbo.T_Delivery_Pattern_Master E
ON A.I_Delivery_Pattern_ID = E.I_Delivery_Pattern_ID
LEFT OUTER JOIN dbo.T_Course_Fee_Plan F
ON B.I_Course_Fee_Plan_ID = F.I_Course_Fee_Plan_ID
ORDER BY C.S_Course_Name


Thanks

Karthik


Responses

Posted by: Bandi on: 6/2/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SELECT DATEADD(DD, ISNULL(A.I_Admission_GraceDays ,0),
A.Dt_BatchStartDate) AS Dt_BatchStartDate

,A.I_Admission_GraceDays
FROM T_Student_Batch_Master A
INNER JOIN T_Center_Batch_Details B
ON B.I_Batch_ID=A.I_Batch_ID
AND B.I_Centre_Id = 767
AND B.I_Status = 4
AND A.AllowOnlineAddmission = 1
INNER JOIN T_Course_Master C
ON C.I_Course_ID= A.I_Course_ID
AND C.I_CourseFamily_ID = 535
AND C.I_Brand_ID = 1
--AND A.Dt_BatchStartDate > GETDATE()
INNER JOIN dbo.T_Delivery_Pattern_Master E
ON A.I_Delivery_Pattern_ID = E.I_Delivery_Pattern_ID
LEFT OUTER JOIN dbo.T_Course_Fee_Plan F
ON B.I_Course_Fee_Plan_ID = F.I_Course_Fee_Plan_ID
ORDER BY C.S_Course_Name


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

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

Posted by: Vuyiswamb on: 6/2/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
DateAdd function is the answer to your problem , check here how it works

http://msdn.microsoft.com/en-us/library/ms186819.aspx

Thank you for posting at Dotnetfunda
[Administrator]

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

Login to post response