Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jim65
Starting Member
35 Posts |
Posted - 2006-04-10 : 13:43:52
|
| I have a stored procedure which insert the record into the adReportingRequirement table. then call user defined function to get a due date. after that, insert the record into the adReportingRequirementHistory table, it looks like run forerver and didn't insert any data into the adReportingRequirementHistory table.CREATE PROCEDURE asp_InsertReportingRequirement_test (@EntityID int, @RptReqTypeID int, @FrequencyID int, @DaysUntilDue int, @StartDate smalldatetime, @EndDate smalldatetime) ASset nocount on--inserts record into reportingRequirement table using parameters passed in from the front endINSERT INTO adReportingRequirement (EntityID, RptReqTypeID, FrequencyID, DaysUntilDue, StartDate, EndDate)VALUES (@EntityID, @RptReqTypeID, @FrequencyID, @DaysUntilDue, @StartDate, @EndDate)--get my newly inserted record IDDeclare @NewRecord intSELECT @NewRecord = @@IdentityDECLARE @FYE AS smalldatetime SELECT @FYE = ContactFYE FROM dashboard.dbo.adBorrowerEntityWhere EntityID = @EntityID-- calls the User Defined Function dbo.udfNEW_DueDate to get my due date based on the start date and due date from the userDeclare @DateDue smalldatetimeDECLARE @MonthCount as int SET @MonthCount =1 Declare @ExpireDate smalldatetimebegin while @MonthCount < =12Select @DateDue = dbo.udfNEW_DueDate(@FYE, @DaysUntilDue,@MonthCount)-- calls the User Defined Function udfNextHistory to get my expiration date based on the start date and frequency from the userSelect @ExpireDate= dbo.udfNextHistory(@FYE, @FrequencyID)-- Inserts the first History record into the Reporting requirement history table with my newly created Identity from the Reporting Requirement table and defined dates aboveINSERT INTO adReportingRequirementHistory (RptReqID, PeriodDate, DateDue, ExpireDate)VALUES (@NewRecord, @StartDate, @DateDue, @ExpireDate)SET @MonthCount = @MonthCount + 1end goCREATE FUNCTION dbo.udfNEW_DueDate (@FYE smalldatetime, @Duedays int, @monthCount int ) RETURNS smalldatetime AS BEGIN DECLARE @Return_temp_String AS smalldatetime DECLARE @ReturnString AS smalldatetime select @Return_temp_String = (select convert (datetime, convert (Char(8), ( DATEADD (dd , @Duedays, @FYE) ), 112)))select @ReturnString = (select convert (datetime, convert (Char(8), ( DATEADD (mm , @monthCount, @Return_temp_String) ), 112)))Return @ReturnStringEND |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-04-10 : 13:53:30
|
I think the following may be the causebegin while @MonthCount < =12begin Select @DateDue = dbo.udfNEW_DueDate(@FYE, @DaysUntilDue,@MonthCount)-- calls the User Defined Function udfNextHistory to get my expiration date based on the start date and frequency from the userSelect @ExpireDate= dbo.udfNextHistory(@FYE, @FrequencyID)-- Inserts the first History record into the Reporting requirement history table with my newly created Identity from the Reporting Requirement table and defined dates aboveINSERT INTO adReportingRequirementHistory(RptReqID, PeriodDate, DateDue, ExpireDate)VALUES (@NewRecord, @StartDate, @DateDue, @ExpireDate)SET @MonthCount = @MonthCount + 1end Srinika |
 |
|
|
jim65
Starting Member
35 Posts |
Posted - 2006-04-10 : 14:09:15
|
| Thanks, you are right. |
 |
|
|
|
|
|
|
|