Hey guys,
i am going to create SI for each record of table ,getting error from STORED PROCEDURE.
No column name was specified for column 6 of 'cte_Alldates'.
please check the bellow script and let me know,where is the problem
Table script :
and the STORE PROCEDURE :
create proc sp_calcualtteSI
as
begin
DECLARE @today datetime
SET @today = dateadd(day,datediff(day,0,current_timestamp),0)
; with cte_dates
as
(
select distinct name,Pamount,Rateofint
,cdate
,case when isnull(@today,@today) < dateadd(month,1,dateadd(month,datediff(month,0,cdate),0))
then isnull(@today,@today)
else dateadd(month,1,dateadd(month,datediff(month,0,cdate),0))
end as MonthEnd
,isnull(@today,@today) as End_date
FROM tbl_intestcalculate
) ,
cte_Alldates
as
(
select name,Pamount,Rateofint
, cdate
,monthEnd
,@today
from cte_dates
union
select name,Pamount,Rateofint
, dateadd(month,number,monthEnd)
,case when dateadd(month,number+1,monthEnd) < @today
then dateadd(month,number+1,monthEnd)
else @today
end
,@today
from cte_dates c
cross join (select number from master..spt_values where type = 'p' and number between 0 and 11) a
where dateadd(month,number,monthEnd) < @today
)
select name
,cdate
,monthEnd
,Pamount
,Rateofint
,datediff(day,cdate,monthEnd) as No_Of_Days
,round(Pamount*Rateofint*datediff(day,cdate,monthEnd)/36500,2) as SI
from cte_Alldates
end
Shubham KumarPosted Feb 6, 2016, 4:58 AM
Shubham KumarPosted Feb 6, 2016, 5:23 AM
amit varmaPosted Feb 6, 2016, 5:21 AM
Shubham KumarPosted Feb 6, 2016, 5:14 AM
AS
BEGIN
DECLARE @today DATETIME
SET @today = DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 0);
WITH cte_dates
AS ( SELECT DISTINCT
name ,
Pamount ,
Rateofint ,
cdate ,
CASE WHEN ISNULL(@today, @today) < DATEADD(MONTH,
1,
DATEADD(MONTH,
DATEDIFF(MONTH,
0, cdate), 0))
THEN ISNULL(@today, @today)
ELSE DATEADD(MONTH, 1,
DATEADD(MONTH,
DATEDIFF(MONTH,
0, cdate), 0))
END AS MonthEnd ,
ISNULL(@today, @today) AS End_date
FROM tbl_intestcalculate
),
cte_Alldates
AS ( SELECT name ,
Pamount ,
Rateofint ,
cdate ,
MonthEnd ,
@today AS today
FROM cte_dates
UNION
SELECT name ,
Pamount ,
Rateofint ,
DATEADD(MONTH, number, MonthEnd) ,
CASE WHEN DATEADD(MONTH, number + 1,
MonthEnd) < @today
THEN DATEADD(MONTH, number + 1,
MonthEnd)
ELSE @today
END ,
@today
FROM cte_dates c
CROSS JOIN ( SELECT number
FROM master..spt_values
WHERE type = 'p'
AND number BETWEEN 0 AND 11
) a
WHERE DATEADD(MONTH, number, MonthEnd) < @today
)
SELECT name ,
cdate ,
MonthEnd ,
Pamount ,
Rateofint ,
DATEDIFF(DAY, cdate, MonthEnd) AS No_Of_Days ,
ROUND( CAST(Pamount AS INT) * CAST(Rateofint AS INT) * DATEDIFF(DAY, cdate, MonthEnd)/ 36500, 2) AS SI
FROM cte_Alldates
END
Shubham KumarPosted Feb 6, 2016, 5:08 AM
amit varmaPosted Feb 6, 2016, 5:06 AM
amit varmaPosted Feb 6, 2016, 5:05 AM
amit varmaPosted Feb 6, 2016, 4:56 AM
Shubham KumarPosted Feb 6, 2016, 4:55 AM