| Author |
Topic |
|
VeselaApo
Posting Yak Master
114 Posts |
Posted - 2010-11-30 : 19:03:53
|
| Hi I have the following procedure: Create Procedure AmortScenarios (@Contract DATETIME) as Begin Declare @Contract_Length int Set @Contract_Length = (select COUNT(CAl_date) from #amort_36mo where (Cal_date) = @Contract) while @contract_length >= 1 set @Contract_Length = @Contract_Length - 1End Declare @Monthly_Amorti int; Set @monthly_amorti = (select (SUM(quarterly_main_fee) + SUM(fees))/@Contract_Lengthfrom #amort_36mo)_____________The procedure executes successfully but when I call the procedure using this command, it gives me an error: call AmortScenarios ('2015-12-28') Error:Incorrect syntax near '2015-12-28'.Can anyone help me why this is happening? thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
VeselaApo
Posting Yak Master
114 Posts |
Posted - 2010-11-30 : 19:10:05
|
| thanks Tara! it worked - however I am getting another error now - Divide by zero error encountered. where could the problem be? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
VeselaApo
Posting Yak Master
114 Posts |
Posted - 2010-11-30 : 19:25:45
|
| well the value @contract_length is not supposed to be zero...do you know why my constraints are not executing properly? thanks! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
VeselaApo
Posting Yak Master
114 Posts |
Posted - 2010-11-30 : 19:34:40
|
| Ok so I replaced the @contract_length with the number and now I am not getting any errors. However, I cannot see the results from the executed procedure? How do I display the results? This is the most recent code: Create Procedure AmortScenarios (@Contract DATETIME) as Declare @Contract_Length int Set @Contract_Length = (select COUNT(CAl_date) from #amort_36mo where (Cal_date) = @Contract) ----while @contract_length > 1 ----set @Contract_Length = @Contract_Length - 1 Declare @Monthly_Amorti int; Set @monthly_amorti = (select (SUM(quarterly_main_fee) + SUM(fees))/10-----@Contract_Lengthfrom #amort_36mo) exec AmortScenarios '2014-12-28' drop procedure AmortScenarios |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-12-01 : 02:15:23
|
| You need to SELECT the variableCreate Procedure AmortScenarios (@Contract DATETIME) as Declare @Contract_Length intSet @Contract_Length = (select COUNT(CAl_date) from #amort_36mo where (Cal_date) = @Contract)----while @contract_length > 1----set @Contract_Length = @Contract_Length - 1Declare @Monthly_Amorti int;Set @monthly_amorti = (select (SUM(quarterly_main_fee) + SUM(fees))/10-----@Contract_Lengthfrom #amort_36mo)SELECT @monthly_amorti GOexec AmortScenarios '20141228' Also see why you need to use unambigious date formathttp://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
VeselaApo
Posting Yak Master
114 Posts |
Posted - 2010-12-01 : 13:46:28
|
| yes this is absolutely correct - i needed to select the results into the table. everything works now - thanks! |
 |
|
|
|